Question

Compare support for strings in C/C++ with another language in hhterms of pros/cons and similarities/differences. Provide...

Compare support for strings in C/C++ with another language in hhterms of pros/cons and similarities/differences. Provide specific coding examples.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer)

A string in C/C++ and other high-level languages such as python is an array of characters. In C then end of the string is determined by a terminating null character '\0'.  

There are a number of methods available for working with strings in C/C++ are below and comparing the same method in a high-level language such as python:

1) In C we have <string.h> library predefined which provides support for String. It provides methods such as strcat() it concatenates two strings.

Example:

char str1[] = "hello", str2[] = "world";
strcat(str1,str2);

It combines str1 and str2 and the result is stored back in str1.

In python, we can just use '+' to concatenate strings.

Example: s1= "Hello" , s2="world"

s3= s1 + s2

The result is stored in s3 that is hello world. The advantage compared to c is that it does not require to import the library.

2) In C/C++ strings are mutable which means that we can change the content of the string. Whereas, In other languages such as java and python strings are immutable.

3) In C strlen() used to find the length of the string. In python len() methods return the length of the array.

Example: a="hello";

strlen(a); // gives 5 in C.

len(a); // gives 5 in python

Add a comment
Know the answer?
Add Answer to:
Compare support for strings in C/C++ with another language in hhterms of pros/cons and similarities/differences. Provide...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT