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 4 of 4.
Trishul said:
8 years ago
Here charp is pointer to a character type.
Where as p is a constant of charp type not char type.
There is no option which says this.
The only option is the first one which tells it is a constat.
Where as p is a constant of charp type not char type.
There is no option which says this.
The only option is the first one which tells it is a constat.
Som said:
8 years ago
Can anyone explain how the const charp P is expanded?
If it is expanded as const char* P, then it means it is a pointer to a character constant.
Hence ++P must be allowed and (*P)++ must not be allowed.
But while compiling the error is thrown for ++P saying that P is a constant and (*P)++ is error free.
If it is expanded as const char* P, then it means it is a pointer to a character constant.
Hence ++P must be allowed and (*P)++ must not be allowed.
But while compiling the error is thrown for ++P saying that P is a constant and (*P)++ is error free.
Pooja said:
6 years ago
I think p is constant only.
Jethalal said:
5 years ago
@Pooja No, I think it should be a pointer to a character constant only.
(1)
Jayesh said:
4 years ago
I agree with you @Santosh.
Mladen Saldanha said:
5 months ago
@All.
typedef char *charp;
This defines charp as a pointer to char (equivalent to char*).
const charp P;
This declares P as a constant pointer to char (not a pointer to a constant char).
The const applies to the pointer itself, not the data it points to.
So, it should be none of the above.
typedef char *charp;
This defines charp as a pointer to char (equivalent to char*).
const charp P;
This declares P as a constant pointer to char (not a pointer to a constant char).
The const applies to the pointer itself, not the data it points to.
So, it should be none of the above.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers