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

Discussion

Point out the error in the program

#include <stdio.h>

int main()
{
    int i;
    #if A
        printf("Enter any number:");
        scanf("%d", &i);
    #elif B
        printf("The number is odd");
    return 0;
}

 

  • A.Error: unexpected end of file because there is no matching #endif
  • B.The number is odd
  • C.Garbage values
  • D.None of above

Answer: A

Correct answer: Error: unexpected end of file because there is no matching #endif

Every #if, #ifdef or #ifndef must be closed by an #endif. Here the conditional started by #if A and continued by #elif B is never closed, so the preprocessor runs off the end of the file and reports it. Note that this is a preprocessing error, so it is reported before any of the C is looked at.

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

Post your comment

Please log in or register to post a comment.