What is the difference between char a = "string"; and
char *p = "string"; ?
Answers were Sorted based on User's Feedback
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|
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|
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|
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
In char *p address can be change string cant be change
|Is This Answer Correct ?||15 Yes||3 No|
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
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
|Is This Answer Correct ?||8 Yes||3 No|
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
|Is This Answer Correct ?||6 Yes||3 No|
Answer / ashok
Pointers are fine a cannot be changed p can be changed.
I have a doubt like is there any difference in memory
I heard like a gets its memory in local stack and p gets in
I don get the clear explanation
|Is This Answer Correct ?||3 Yes||4 No|
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|
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 = '2',....
|Is This Answer Correct ?||1 Yes||3 No|
to print the salary of an employee according to follwing calculation: Allowances:HRA-20% of BASIC,DA-45% of BASIC,TA-10%. Deductions:EPF-8% of BASIC,LIC-Rs.200/-Prof.Tax:Rs.200/- create c language program?
write a C program: To recognize date of any format even formats like "feb-02-2003","02-february-2003",mm/dd/yy, dd/mm/yy and display it as mm/dd/yy.
what does keyword ‘extern’ mean in a function declaration?
what are bitwise shift operators?
advantages of pointers?
write a own function for strstr
Prove or disprove P!=NP.
which is faster execution: loops or recursion?
1 1 2 1 2 3 1 2 3 4 1 2 3 1 2 1 generate this output using for loop
difference between native and cross compilers
1.int a=10; 2.int b=20; 3. //write here 4.b=30; Write code at line 3 so that when the value of b is changed variable a should automatically change with same value as b. 5.
what defference between c and c++ ?