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

main use of recursive function a) processing speed high b) reduce program length/reduce repeated statements c) if you do not, use iterative methods like, for, while or do-while d) all the above

0 Answers  


What are the advantages and disadvantages of pointers?

0 Answers  


Write a program in C to convert date displayed in gregorian to julian date

0 Answers   HCL, Wipro,


Why c is called procedure oriented language?

0 Answers  


the operator for exponencation is a.** b.^ c.% d.not available

5 Answers   TCS,






what is c?

4 Answers   IBM, TCS,


What are advantages and disadvantages of recursive calling ?

12 Answers   College School Exams Tests, Evolving Systems, HP, Jyoti Ltd, Sage, Wipro,


What are c preprocessors?

0 Answers  


Explain about block scope in c?

0 Answers  


please explain clearly about execution of c program in detail,in which stage are the printf sacnf getting into exeecutable code

0 Answers   Mind Tree,


What is an array? What the different types of arrays in c?

0 Answers  


What is variable and explain rules to declare variable in c?

0 Answers  


Categories