C Programming - Strings - Discussion


Is there any difference between the two statements?
char *ch = "IndiaBIX";
char ch[] = "IndiaBIX";

[A]. Yes
[B]. No

Answer: Option A


In first statement the character pointer ch stores the address of the string "IndiaBIX".
The second statement specifies the space for 7 characters be allocated and that the name of location is ch.

James said: (Aug 14, 2015)  
It would be 9 characters - 8 plus one for NULL.

Akshay Immanuel said: (Jul 2, 2016)  
By dereferencing the pointer and the array, won't they be the same?

Like ch[3] (pointer declaration of ch) == ch[3] (array declaration of ch)?

Ramandeep said: (May 25, 2017)  
Yes, you are Right @James.

Arda said: (Jun 8, 2019)  
So for both cases what is ch[0], ch[1], ch[2], ch and *ch?

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.