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 2 of 4.

Manju said:   1 decade ago
ptr is an pointer variable, so the variable stored in pointer only.

Anis gupta said:   1 decade ago
Hi, typedef act as syntax replacement so simply.

ptr replace with int *,
So it is int *p1,p2;

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'.

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

Ganesh said:   9 years ago
What is type def?

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

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.

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

Akash said:   5 years ago
@Parin.

Your explanation is very clear, Thanks.

Pankaj said:   1 decade ago
We defined value at ptr(*ptr) as integer. So p1 and p2 not storing the adress their is they are storing value.

#include<stdio.h>
int main()
{
typedef int *ptr;
ptr p1, p2;
printf("%d %d",p1,p2);
}

o/p: 0 0


Post your comments here:

Your comments will be displayed after verification.