What is the difference between character array and string in C?

Questions by ravi.dokania   answers by ravi.dokania

Showing Answers 1 - 7 of 7 Answers

malaram

  • Feb 6th, 2007
 

I think there is nothing difference b/w both because string is a collection of character or we can say it is a character array which ends at NULL.

  Was this answer useful?  Yes

Amit_21

  • Jan 31st, 2008
 

IN C there is no big diffrence Between string and character array
 
 but string must be NULL terminated...... if u ll forget to insert the '' at the END it will automatically insert the NULL chracter .take a example

int i;
char arr[5]={'a','s','d','z','x'};  \no error because not a string..it is collection of chracter
char arr1[5]="asdzx";   //error overflow because last chracter must be
char arr2[6]="asdzx";//will work
for (i=0;i<5;printf("n%d----%cn",i,arr[i]),i++);

printf("nstringn ");
printf("nstring-----is ----%sn",arr1);


hi,guys..this is amit what i feel abto arrayand string i already written ..if u have any other views plz send me at amitsrms21@gmail.com

  Was this answer useful?  Yes

vanavill

  • Feb 8th, 2008
 


 Hai,
    string is a collection of charecter,it must be ended with null.
     charecter array is aset of elements if you didn't give a space for null,it shows error.
    
   if any correction or further infn plz send it to me.

regrads,
bala.

  Was this answer useful?  Yes

kushal

  • Dec 26th, 2011
 

char arr2[6]="asdzx";//will work


this instruction never work....
ok

  Was this answer useful?  Yes

udaykiran

  • Feb 8th, 2012
 

the major difference between the char array and the string is that the array will not end with the null....where as string ends with the null.............

  Was this answer useful?  Yes

vijay

  • Sep 6th, 2016
 

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

  Was this answer useful?  Yes

jbode

  • Sep 16th, 2016
 

In C, a *string* is a sequence of character values followed by a zero-valued terminator (byte or byte sequence). Strings are *stored* as arrays of char, but not all arrays of char contain strings - if that null terminator isnt there, then the array does not contain a string.
A *string literal* like "Hello" is also stored as an array of char such that it is allocated when the program starts and is available over the lifetime of the program. Attempting to modify the contents of a string literal invokes undefined behavior, so you cant use a string literal (or a pointer variable that points to the beginning of a string literal) as an argument to a function that tries to modify the string (strcpy, strcat, strtok, etc.).

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions