in Programming in C
771 views
1 vote
1 vote

For the following “typedef” in C, pick the best statement

typedef int INT, *INTPTR, ONEDARR[10], TWODARR[10][10];

A

It will cause compile error because typedef is being used to define multiple aliases of incompatible types in the same statement.

B

“INT x” would define x of type int. Remaining part of the statement would be ignored.

C

“INT x” would define x of type int and “INTPTR y” would define pointer y of type int *. Remaining part of the statement would be ignored.

D

“INT x” would define x of type int. “INTPTR y” would define pointer y of type int *. ONEDARR is an array of 10 int. TWODARR is a 2D array of 10 by 10 int.

E

“INT x” would define x of type int. “INTPTR *y” would define pointer y of type int **. “ONEDARR z” would define z as array of 10 int. “TWODARR t” would define t as array of 10 by 10 int.

in Programming in C
771 views

4 Comments

Follow Habibkhan  link provided in comment
0
0
I already did that before. It does not explain about why Option D is wrong. It explains why option E is right.
0
0

Since the question asks for: "Pick the best statement" so I think E) is more appropriate. For D) this part is correct : “INT x” would define x of type int. “INTPTR y” would define pointer y of type int * but for the rest part E is more appropriate.

0
0

1 Answer

0 votes
0 votes
Answer E)

INT is alias of int. INTPTR is alias of int *. That’s why INTPTR * would be alias of int **. Similarly, ONEDARR is defining the alias not array itself. ONEDARR would be alias to int [10]. That’s why “ONEDARR z” would define array z of int [10]. Similarly, TWODARR would be alias to int [10][10]. Hence “TWODARR t” would define array t of int [10][10]. We can see that typedef can be used to create alias or synonym of other types.