Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


what is the difference between char * const and const char
*?

Answers were Sorted based on User's Feedback



what is the difference between char * const and const char *?..

Answer / brindha

Char* const p -> Here pointer P is a const pointer, which
means that this pointer can point to only one memory
location. eg. char* const p = &arr;
p++ ; -> This is invalid


const char* p -> this indicates that the data pointed by
the pointer p is constant & the value in that address
cannot be modified. eg. const char* p = 'a';
*p = 'b'; -> This is invalid

Is This Answer Correct ?    30 Yes 2 No

what is the difference between char * const and const char *?..

Answer / yathish nm yadav

CHAR * CONST
means we are making the variable of type
char* as constant i.e,
ex:
char * const p;
means pointer variable p is made constant i.e, its lvalue
is been blocked by compiler at compile time.
ex:
char c;
char *const p= &c;
here p contains the adress of c and we cannot make p now to
point to some other variable.
char t;
p=t; //compile time error.

CONST CHAR *
means the variable pointed to by the const char * is made
constant. i,e.
ex:
char c='a';
const char *p=&c;
here c is made constant n its lvalue is being blocked.
now we cannot change the value of c since it is made
constant.
i.e,
*p='b'; // error

Is This Answer Correct ?    2 Yes 0 No

Post New Answer

More C Interview Questions

how the size of an integer is decided? - is it based on processor or compiler or OS?

19 Answers   HCL, JPR, Microsoft, nvidia,


what is calloc and malloc?

2 Answers  


What are the advantages of union?

0 Answers  


convert 0.9375 to binary

2 Answers   CTS, TANCET,


What is the value of uninitialized variable in c?

0 Answers  






Describe the difference between = and == symbols in c programming?

0 Answers  


C program code int zap(int n) { if(n<=1)then zap=1; else zap=zap(n-3)+zap(n-1); } then the call zap(6) gives the values of zap [a] 8 [b] 9 [c] 6 [d] 12 [e] 15

6 Answers   TCS, Wipro,


hi any body pls give me company name interview conduct "c" language only

0 Answers  


What is cohesion in c?

0 Answers  


What is assignment operator?

0 Answers  


WAP TO ACCEPT STRING AND COUNT A COMES N TIMES B COMES N TIMES C COMES N TIMES D COMES N TIMES AND SO ON......... AT LAST UNTIL Z COMES N TIMES...............

3 Answers  


How will you find a duplicate number in a array without negating the nos ?

0 Answers  






Categories