C Programming - Strings - Discussion
Discussion Forum : Strings - Point Out Correct Statements (Q.No. 2)
2.
Which of the following statements are correct about the below declarations?
char *p = "Sanjay";
char a[] = "Sanjay";
char *p = "Sanjay";
char a[] = "Sanjay";
1: | There is no difference in the declarations and both serve the same purpose. |
2: | p is a non-const pointer pointing to a non-const string, whereas a is a const pointer pointing to a non-const pointer. |
3: | The pointer p can be modified to point to another string, whereas the individual characters within array a can be changed. |
4: | In both cases the '\0' will be added at the end of the string "Sanjay". |
Discussion:
17 comments Page 2 of 2.
Ronil said:
1 decade ago
Is null character added at the end of 2nd statement?I think. Its wrong.
In 1st case null char is added. But for 2nd its wrong.
In 1st case null char is added. But for 2nd its wrong.
Ravi said:
1 decade ago
I think option 2 is not correct. We cannot modify the string "Sanjay".
Ahok said:
1 decade ago
What is the meaning of second statement given in the question?
Anusha said:
1 decade ago
I'm not understanding any answer please explain clearly.
Jahnavi said:
1 decade ago
I'm not understsanding second option please explain.
Kaustav said:
1 decade ago
"a" is not a pointer. It is declared as char.
Shruti said:
1 decade ago
Why can't the 1st option be correct?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers