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;
P is a constant
P is a character constant
P is character type
None of above
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
36 comments Page 2 of 4.

Atul said:   1 decade ago
P is the pointer to char constant

Muneesh said:   8 years ago
How is this possible?

Venkatesh said:   8 years ago
Can someone explain clearly?

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.

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.

Pooja said:   6 years ago
I think p is constant only.

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.

Ana said:   1 decade ago
The answer is no clear to me. Can some one please explain.

ASHOK G said:   2 decades ago
I guess P is a pointer to a const char.


Post your comments here:

Your comments will be displayed after verification.