Given typedef int *intptr; the declaration intptr a, b; differs from a #define of intptr for int * in which respect?
Correct answer
A. The typedef makes both a and b pointers; the macro makes only a pointer
20 views
A. The typedef makes both a and b pointers; the macro makes only a pointer
20 views
A typedef introduces a new type name, so intptr a, b; declares two objects of that pointer type. A macro performs token substitution, so intptr a, b; becomes int *a, b; and only a is a pointer while b is a plain int. This is why pointer typedefs are common in API headers and why the * in a declarator binds to the name, not to the type specifier.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is A? Ask here and get an explanation.