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 / srinivas

a is a const pointer, whereas p is not
meaning 'a' will point to a fixed location (value of 'a' or
address of *a can't change, remains fixed) - though
contents of a can be changed (by way of accessing a[i])

Is This Answer Correct ?    36 Yes 6 No

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

Answer / singamsa

we can not access a++ or a-- on array but we can do that in
pointers

array, address is constanct for that string, pointer is not
like that

Is This Answer Correct ?    43 Yes 22 No

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

Answer / praveenkumar managuli

char s[]; this allocate memory equal tosize of string
and char *s; holds the address of first charecter

Is This Answer Correct ?    23 Yes 4 No




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

Answer / abc

we cannot assign a string to another but we can assign a
char pointer to another char pointer.

Is This Answer Correct ?    23 Yes 7 No

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

Answer / karuna

a[] is a constant pointer to a string;

char *p is a pointer to a constant string;

In a[] address of a[] cant be change but string can be
change.

In char *p address can be change string cant be change

Is This Answer Correct ?    15 Yes 3 No

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

Answer / kurvatis

When a program starts its content copies from external
memory like a hard drive to a PROTECTED from writes part of
RAM. No any byte in that area can be changed!

Now the difference.
char * p = "this string is in protected memory and cannot be
changed";
You cannot change the string located in protected memory a
pointer points to.


char a[] = "this string is in memory that can be changed";

Theoretically char * p = "string"; eat less memory than
another one.

Is This Answer Correct ?    8 Yes 3 No

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

Answer / ashwin kumar

just one word i can say that
a[] is static memory allocation ( we cant increase size of
array while execution of program )
*p is a dynamic memory allocation ( where we can use
according to our requirement while execution )

their may be a waste age of memory and also their may be
limitaion of elements in array.

memory will not be wasted and size depends up on our
require ment in pointes

i hope its may be one of the defferance

if thier is any feed back or my answer is wrong plz write
to molugu.aswin@gmail.com

Is This Answer Correct ?    6 Yes 3 No

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

Answer / ashok

Pointers are fine a cannot be changed p can be changed.

I have a doubt like is there any difference in memory
allocation.

I heard like a gets its memory in local stack and p gets in
data section.

I don get the clear explanation

Is This Answer Correct ?    3 Yes 4 No

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

Answer / mak

in case of array size of it become fixed after initialization,
so a string of length greater than the size of previous string can't be assigned to array.
on the other hand pointer can take variable size string as it stores only the first address.

Is This Answer Correct ?    0 Yes 1 No

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

Post New Answer



More C Interview Questions

1) There is a singing competition for children going to be conducted at a local club. Parents have been asked to arrive at least an hour before and register their children’s names with the Program Manager. Whenever a participant registers, the Program Manager has to position the name of the person in a list in alphabet order. Write a program to help the Program Manager do this by placing the name in the right place each time the Program Manger enters a name. 2) the Event Manager has to send participants to the stage to perform in the order in which they registered. Write a program that will help the Event Manager know who to call to the stage to perform. The Logic should be in Data Structures

0 Answers   KPIT,


There are 8 billiard balls, and one of them is slightly heavier, but the only way to tell was by putting it on a weighing scale against another. What's the fewest number of times you'd have to use the scale to find the heavier ball?

5 Answers   Microsoft, TCS,


what is pointer ?

10 Answers   Kernex Micro Systems,


write a “Hello World” program in “c” without using a semicolon?

9 Answers   TCS, Wipro, CTS,


Derive the complexity expression for AVL tree?

1 Answers  






what is the purpose of the following code, and is there any problem with the code? void fn(long* p1, long* p2) { register int x = *p1; register int y = *p2; x ^= y; y ^= x; x ^= y; *p1 = x; *p2 = y; }

1 Answers   Google,


what is the c source code for the below output? 1 0 1 1 0 1 0 1 0 1 1 0 1 0 1

0 Answers  


What is Generic pointer? What is the purpose of Generic pointer? Where it is used?

3 Answers  


write a program in c to find out the sum of digits of a number.but here is a condition that compiler sums the value from left to right....not right to left..

1 Answers  


is it possible to change the default calling convention in c ?

1 Answers   Aptech,


What is the output of below code? main() { static in a=5; printf("%3d",a--); if(a) main(); }

4 Answers   TCS, Infosys,


Find the middle node in the linked list?? (Note:Do not use for loop, count and count/2)

6 Answers   Subex,






Categories