C Programming - Typedef - Discussion

Discussion Forum : Typedef - General Questions (Q.No. 1)
1.
In the following code, the P2 is Integer Pointer or Integer?
typedef int *ptr;
ptr p1, p2;
Integer
Integer pointer
Error in declaration
None of above
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
36 comments Page 1 of 4.

Akash said:   5 years ago
@Ruhi.

It will change the name of int* as ptr.
(1)

Akash said:   5 years ago
@Parin.

Your explanation is very clear, Thanks.

Jethalal said:   5 years ago
@Ruhi, Yes I also have the same doubt.

Ruhi said:   6 years ago
How is it possible?

Whenever we use typedef, that means we are renaming the previously defined keyword or variable.

If we have declared,

Typedef int *ptr;

That means simply we have renamed, int as *ptr. Then how did it become a pointer?

Please answer me with a clear explanation.
(1)

Prasanth said:   8 years ago
Can we say like this?

*ptr is the name used instead of int and
ptr defines the variables as p1 and p2.
but how to compare the both *ptr and ptr.

Amit Saxena said:   9 years ago
@All.
I think we should try the given codes in c compiler provided.

@Pankaj.
I tried your code and definitely p1 and p2 are working as an integer, not as integer pointers.
(2)

AKSHAY KALRA said:   9 years ago
@Ganesh, @Ashok.

Typedef basically allows us to represent a data type with a new identifier.
Note---> typedef type identifier.

Therefore, ptr is not a pointer variable. It is just an identifier which represents integer pointer.

typedef int *ptr; // equivalent to typedef int * ptr
Hence, ptr p1,p2 // equivalent to int *p1, int *p2

Ganesh said:   9 years ago
What is type def?

Ashok said:   10 years ago
I can't understand the typedef operation?

Nikky Aaryan said:   1 decade ago
*ptr is address of the variables and p1 & p2 are the integers.

int *ptr is nothing but the 'address of the variables are integers'.


Post your comments here:

Your comments will be displayed after verification.