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

Here is a good puzzle: how do you write a program which produces its own source code as output?

0 Answers  


program for following output using for loop? 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5

8 Answers   Aptech, Infosys,


a=10;b= 5;c=3;d=3; if(a printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d);

0 Answers   Wilco,


please give me answer with details #include<stdio.h> main() { int i=1; i=(++i)*(++i)*(++i); printf("%d",i); getch(); }

3 Answers  


Explain this code. #include <stdio.h> void f1(int *k) { *k = *k + 10; } main ( ){ int i; i = 0; printf (" The value of i before call %d \n", i); f1 (&i); printf (" The value of i after call %d \n", i); }

3 Answers   IBM,






what are two kinds of java

2 Answers  


wats the diference btwen constant pointer and pointer to a constant.pls give examples.

9 Answers  


What is meant by inheritance?

0 Answers  


enum DAY { sunday, monday, tuesday }; enum EDAYS { friday, saturday, sunday }; void main() { int i =0; if( i == sunday) { printf("%d",i); } } what would be the output?

4 Answers   TCS,


please give code for this 1 2 4 7 11 16

11 Answers   Intel, Wipro,


Reverse the part of the number which is present from position i to j. Print the new number.[without using the array] eg: num=789876 i=2 j=5 778986

2 Answers  


the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none

0 Answers  


Categories