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;
Discussion:
36 comments Page 3 of 4.
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 *;
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 *;
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.
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.
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.
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.
Lakshmi prasanna said:
1 decade ago
ptr is an integer pointer. Hence both the variables store the pointers.
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;
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'.
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
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
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers