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.
Sunil said:
1 decade ago
Then whether p1 is an integer. Please answer any one with explanation.
Lordy said:
1 decade ago
@sunil
p1 is just a pointer. it is not declared as int so how can that be integer. think u will understand clearly.
p1 is just a pointer. it is not declared as int so how can that be integer. think u will understand clearly.
Jigar said:
1 decade ago
@lordy
but ptr is integer type pointer so i think indirectly p1 is also integer
but ptr is integer type pointer so i think indirectly p1 is also integer
Vengatraman said:
1 decade ago
Becoz p1, p2 s assigned as ptr var & ptr is defined as integer. So I think as it is integer pointer.
Nishant said:
1 decade ago
ptr is the pointer which has the address at which value is stored.And p2 is defined as ptr so p2 is the integer pointer which has the address at which has integer value...
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.
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.
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.
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.
Kumaran said:
1 decade ago
Here we declared ptr as a pointer variable. Using that we can assign two pointers. First one hold the address of Ptr variable. And second one points the address of the first variable. Here the declaration is correct. And p1, p2 are not integers. So B is the answer.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers