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 2 of 4.
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.
Rocky said:
1 decade ago
p is constant or p is character constant???
please answer!!!!
please answer!!!!
Ravi said:
1 decade ago
P is a pointer to a constant.
Because,
Const char *p;.
Because,
Const char *p;.
Ganga said:
1 decade ago
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;
*P=4; //ERROR
P=&a; //Works char a;
Asd said:
1 decade ago
I think finally answer is p is a pointer to a character constant which is not in option so anwer is d.
Rupinderjit said:
1 decade ago
p can't be pointer, since with typedef we can't modify the actual base type,we just only give new name to existing type. That's all folks.
Lijina said:
1 decade ago
Option A is Right,
1. typedef char *charptr;
So charptr contain one address and *charptr contain any constant;
2. const charptr p;
If p='a' and &p=0x10;
Now charptr contain &p(0x10)
Only for address we are keeping const, not for value in that address. So P that is constant.
1. typedef char *charptr;
So charptr contain one address and *charptr contain any constant;
2. const charptr p;
If p='a' and &p=0x10;
Now charptr contain &p(0x10)
Only for address we are keeping const, not for value in that address. So P that is constant.
Atul said:
1 decade ago
P is the pointer to char constant
Chery said:
1 decade ago
P is a pointer to constant of type char.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers