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.

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

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

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

Lakshmi prasanna said:   1 decade ago
ptr is an integer pointer. Hence both the variables store the pointers.

Abhayraj said:   1 decade ago
typedef int *ptr is a ptr declaration & p1,p2 behaves as objects of ptr.

Hence, similar to *ptr & ptr , *p1,*p2 print values at their address & p1, p2 print memory location address. I have compiled on linux gcc.

Please, comment for my answer, for any correction.

Pooja said:   1 decade ago
@Dhanashri.

1). #define: It is used to define micro which are small & faster, it is preprocessor detectives run automatically by compiler by that our source code get changed.

2). typedef: It is keyword used to make variable of particular data type but indirectly.

EX:
typedef char a[]={"dhanashri"};
a b[]={ "pooja"};
where b is char type even though it is indirectly.

Vineet said:   1 decade ago
typedef int *ptr;

Tt means ptr can be used in place of (int *), it is a alais name.

Where we write ptr it means we can substitute it with int *;

Dharshini said:   1 decade ago
Give difference between #define and typedef?

Srees said:   1 decade ago
Lets study each line. For expl typedef int A, if we given means A=int (i. E, we can use A instead of int datatype) so here we have typedef int *ptr (i. E, we can use ptr as int) so ptr p1, p2 means integer pointers.

Aravind said:   1 decade ago
What reason we can use typedef ?

Ramya said:   1 decade ago
@Teju your explanation is very nice and thank you so much.


Post your comments here:

Your comments will be displayed after verification.