Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the output of this program?

#include <stdio.h>
#define p 17;
int main()
{
  printf("%d",p);
  return 0;
}

 

  • A.Garbage value
  • B.Runtime error
  • C.17
  • D.Compilation error

Answer: D

Correct answer: Compilation error

The macro body is 17; - semicolon included. Substituting it gives

printf("%d",17;);

which is a syntax error. This is why a #define for a constant should never end with a semicolon: the macro is text, and the semicolon travels with it wherever the name is used.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.