Interview answers verified by specialists.

Find interview questions and answers on this website:

See right interview answers on 30 common job interview questions

What is the difference between strings and character arrays?

A major difference is: string will have static storage duration, whereas
 as a character array will not, unless it is explicity specified by using the
 static keyword.
 Actually, a string is a character array with following properties:

* the multibyte character sequence, to which we generally call string,
 is used to initialize an array of static storage duration. The size of this
 array is just sufficient to contain these characters plus the terminating
 NUL character.
 * it not specified what happens if this array, i.e., string, is modified.
 * Two strings of same value[1] may share same memory area. For
 example, in the following declarations:
 char *s1 = “Calvin and Hobbes”;
 char *s2 = “Calvin and Hobbes”;
 the strings pointed by s1 and s2 may reside in the same memory
 location. But, it is not true for the following:
 char ca1[] = “Calvin and Hobbes”;
 char ca2[] = “Calvin and Hobbes”;
 [1] The value of a string is the sequence of the values of the contained
 characters, in order.

 Difference between const char* p and char const* p 
 In const char* p, the character pointed by ‘p’ is constant, so u cant
 change the value of character pointed by p but u can make ‘p’ refer to
 some other location.
 in char const* p, the ptr ‘p’ is constant not the character referenced by
 it, so u cant make ‘p’ to reference to any other location but u can
 change the value of the char pointed by ‘p’.

Do you know that?

24% freelancers want to be always solo freelance Next