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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the different types of objects used in c?

558


How can I dynamically allocate arrays?

579


What is function and its example?

612


What is difference between Structure and Unions?

628


What is difference between main and void main?

611






FORMATTED INPUT/OUTPUT functions are a) scanf() and printf() b) gets() and puts() c) getchar() and putchar() d) all the above

608


What is the difference between NULL and NUL?

712


Explain how are portions of a program disabled in demo versions?

637


Explain the difference between call by value and call by reference in c language?

635


Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)

596


Explain what is dynamic data structure?

634


Explain the Difference between the New and Malloc keyword.

674


What is the use of typedef in structure in c?

532


What is unary operator?

646


please give me some tips for the placement in the TCS.

1622