What is the difference between char a[] = "string"; and
char *p = "string"; ?
Answers were Sorted based on User's Feedback
Answer / dharanidhar
P is a pointer which is constant. So, the values in this
array cannot be modified.
characters within a[] can be changed by accessing
like a[1] = '2',....
Is This Answer Correct ? | 1 Yes | 3 No |
Answer / parmjeet kumar
char a[] will alocate the momery size of " string" word in
other hand char *p will alocate the memory size of one
character... or we can not move the data from one location
to another location but with pointer we can do it...
Is This Answer Correct ? | 1 Yes | 5 No |
Answer / ashish
here a is an array and is a char const * data type.
hence u cannot change value of a but u can change the value
which a points to.
p on the other hand is a const char * data type.
hence value of p an be changed but the value p points to
cannot be changed.
i dont know the answer!!! :P
Is This Answer Correct ? | 3 Yes | 13 No |
Answer / aravind
hi im answering as far as i know , pls say ur feedback,,,(+_+)
Array:
for char array char a[]; no such array size is accepted by
the compiler. That is , it requires a fixed size for the
array like: char a[20];
in this case the number of strings / characters it can hold
is only upto 20 while if it exceeds , the input strings get
truncated. [STATIC MEMORY ALLOCATION AND TRAVERSAL WITHIN
BOUNDS]
Pointer:
Whereas in case of pointers it is of DYNAMIC MEMORY type and
infinite storage when compared to Array. and predefinition ,
truncation are absent.
Also TRAVERSAL is easy.
Is This Answer Correct ? | 6 Yes | 23 No |
Write a program that his output 1 12 123
How to avoid buffer overflow?
`write a program to display the recomended action depends on a color of trafic light using nested if statments
Why do u use # before include in a C Progam?
what is the difference b/w NULL and null?
What is sizeof c?
Explain union.
Hai friends im a i year student. i want to develop my knowledge in the field of TSR in c. How I'm Improve ?
string reverse using recursion
why we are using float in C
What is the deal on sprintf_s return value?
What's wrong with "char *p; *p = malloc(10);"?