C Programming - Typedef - Discussion
Discussion Forum : Typedef - General Questions (Q.No. 2)
2.
In the following code what is 'P'?
typedef char *charp;
const charp P;
Discussion:
36 comments Page 3 of 4.
Vinay said:
1 decade ago
P is a character constant.
Shweta Dubey said:
1 decade ago
P is a pointer to a constant
Kumaran said:
1 decade ago
P is the constant... It defined in the outside of main function.
Sunil said:
1 decade ago
here p is constant bcz of usage of keyword const
Santhosh said:
1 decade ago
her p is a pointer to a constant character
Hngn said:
1 decade ago
p is constant chracter pointer
Vikas Sharma said:
1 decade ago
P is a constant pointer.
Jothi basu said:
2 decades ago
P is a character constant using pointer.
Wikiok said:
1 decade ago
typedef char *charp;
const charp P;
so:
const char *P; // The value can not be changed at that memory location, but other memory locations can be used for *P.
*P=4; //ERROR
P=&a; //Works char a;
const charp P;
so:
const char *P; // The value can not be changed at that memory location, but other memory locations can be used for *P.
*P=4; //ERROR
P=&a; //Works char a;
LOL said:
1 decade ago
The trick with const modifier is to read the statement backwards.
const charp P = const char *P;
So reading backwards you have P * char const
which is P is a pointer to a char constant.
const charp P = const char *P;
So reading backwards you have P * char const
which is P is a pointer to a char constant.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers