1. Home
  2. Computer Science MCQs
  3. C Programming
  4. Given typedef int *intptr; the declaration intptr a, b…

Added 30 Nov -0001

Given typedef int *intptr; the declaration intptr a, b; differs from a #define of intptr for int * in which respect?

  1. The typedef makes both a and b pointers; the macro makes only a pointer Correct answer
  2. Both forms declare two pointers, since the tokens are expanded identically
  3. The typedef makes both ints, while the macro makes a pointer and an int
  4. The macro form is a constraint violation and does not compile in C

Correct answer

A. The typedef makes both a and b pointers; the macro makes only a pointer

20 views

MCQSEXAM

Explanation

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.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C Programming MCQs

Practise all C Programming MCQs

Similar MCQs