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

Questions by ravi.dokania   answers by ravi.dokania

Showing Answers 1 - 36 of 36 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

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

Ramakrishna Deshpande

  • Nov 14th, 2016
 

We can change the base address of String where as we cannot modify the address of an Array.
If string is like, char * str = "String" then it cant be modified as it will to RO memory and such operation will result in Segmentation fault, if it is char str[] = "String"; then we can modify this.

  Was this answer useful?  Yes

vamsi

  • Nov 29th, 2016
 

A character array is simply an array of characters
A sting is data structure that uses an array of character.

  Was this answer useful?  Yes

Ganesh kakade

  • Sep 3rd, 2017
 

For accessing the element of character array, we use indexing of array, but in sting we use following syntax as
string_name.charat(index)

  Was this answer useful?  Yes

Dnyaneshwar

  • Sep 6th, 2017
 

Collection of more than one character is known as character array and character array also known string.
There is no data type in like string....

  Was this answer useful?  Yes

Shubhay Raj Dubey

  • Jan 16th, 2018
 

A string must be null terminated whereas character array need not. Hence string requires one bit more space as compared to character arrays

  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.

 

Related Answered Questions

 

Related Open Questions