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

Discussion

Comment on the code below

#include <stdio.h>
    void main()
    {
        int x = 5;
        if (true);
            printf("hello");
    }

 

  • A.It will display hello
  • B.It will throw an error
  • C.Nothing will be displayed
  • D.Compiler dependent

Answer: B

Correct answer: It will throw an error

true is not a keyword in C. It is a macro defined in <stdbool.h>, which this program does not include, so the identifier is undeclared and the program fails to compile. (Had it compiled, the semicolon after the if would have been the empty statement forming its branch, and hello would have printed unconditionally.)

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

Post your comment

Please log in or register to post a comment.