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

On most computers additional memory that is accessed through an adapter of feature card along with a device driver program. a) user memory b) conventional memory c) expandedmemory d) area

0 Answers  


What is calloc malloc realloc in c?

0 Answers  


what is the full form of c language

9 Answers   Satyam, TCS, VNC,


What is structure packing ?

2 Answers   HP,


What are the 3 types of structures?

0 Answers  






Explain what are header files and explain what are its uses in c programming?

0 Answers  


why java is called as a purely oops language.

3 Answers   TVS,


What are the general description for loop statement and available loop types in c?

0 Answers  


write a program to print the consecutive repeated character from the given string... input string is : hhhhjkutskkkkkggggj output should be like this: hhhhkkkkkgggg anyone help me...

0 Answers  


the statement while(i) puts the entire logic in loop. this loop is called a) indefinite loop b) definite loop c) loop syntax wrong d) none of the above

0 Answers  


int x=sizeof(!5.856); What will value of variable x?

2 Answers  


What are # preprocessor operator in c?

0 Answers  


Categories