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

Lakshminaik said:   1 decade ago
Any body help me how to create a struct function how may types.

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);
}

Sai said:   1 decade ago
Excellent martin. Good observation.

Divya said:   1 decade ago
typedef int (*ptr) ;
ptr p1, p2;

What happens in this case ? what will be the type of ptr then ?

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.

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

Parin said:   1 decade ago
Understand the question like this,
typedef (int *) ptr;
ptr p1,p2;

Now it is very clear that p1 and p2 are integer pointers..
(1)

Prasad said:   1 decade ago
*ptr is pointer varible, but when you assign p1 and p2 than p1 is hold the address of ptr but p2 is hold address of p1 ? please answer to me.

Teju said:   1 decade ago
The typedef allows the new name become equivalent to the type you wanted.

Thus, since prt is pointer to integer; p1 and p2 are integer pointers.

Eg:

typedef int arr[7][3];

/* Now declare some objects */

arr a; // Here a is 7*3 array of int.

RAJU said:   1 decade ago
Ptr is pointer to integer. Because p1 and p2 are declared as ptr and ptr is pointer to integer, p1 and p2 both will get the same functionality like integer pointer.


Post your comments here:

Your comments will be displayed after verification.