What is the difference between char a[] = "string"; and
char *p = "string"; ?

Answers were Sorted based on User's Feedback



What is the difference between char a[] = "string"; and char *p = "string"; ?..

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

What is the difference between char a[] = "string"; and char *p = "string"; ?..

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

What is the difference between char a[] = "string"; and char *p = "string"; ?..

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

What is the difference between char a[] = "string"; and char *p = "string"; ?..

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

Post New Answer

More C Interview Questions

Write a program that his output 1 12 123

0 Answers  


How to avoid buffer overflow?

1 Answers  


`write a program to display the recomended action depends on a color of trafic light using nested if statments

0 Answers  


Why do u use # before include in a C Progam?

9 Answers   IBM,


what is the difference b/w NULL and null?

3 Answers   HSBC, IBM,


What is sizeof c?

0 Answers  


Explain union.

0 Answers  


Hai friends im a i year student. i want to develop my knowledge in the field of TSR in c. How I'm Improve ?

2 Answers  


string reverse using recursion

0 Answers   Mind Tree,


why we are using float in C

4 Answers  


What is the deal on sprintf_s return value?

0 Answers  


What's wrong with "char *p; *p = malloc(10);"?

5 Answers  


Categories