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 2 of 4.
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
#include<stdio.h>
int main()
{
typedef int *ptr;
ptr p1, p2;
printf("%d %d",p1,p2);
}
o/p: 0 0
Martin said:
1 decade ago
C is case sensitive and the question clearly asks what P2 is. There is no P2. There is a p2, but that is not the same. Therefore, the answer is D.
Divya said:
1 decade ago
typedef int (*ptr) ;
ptr p1, p2;
What happens in this case ? what will be the type of ptr then ?
ptr p1, p2;
What happens in this case ? what will be the type of ptr then ?
Sai said:
1 decade ago
Excellent martin. Good observation.
Avnish 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);
}
#include<stdio.h>
int main()
{
typedef int *ptr;
ptr p1, p2;
printf("%d %d",p1,p2);
}
Lakshminaik said:
1 decade ago
Any body help me how to create a struct function how may types.
Ramya said:
1 decade ago
@Teju your explanation is very nice and thank you so much.
Aravind said:
1 decade ago
What reason we can use 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.
Dharshini said:
1 decade ago
Give difference between #define and typedef?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers