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

Discussion

Point out the error in the following program.

#include <stdio.h>

int main()
{
    char str[] = "IndiaBIX";
    printf("%.#s %2s", str, str);
    return 0;
}

 

  • A.Error: in Array declaration
  • B.Error: printf statement
  • C.Error: unspecified character in printf
  • D.No error

Answer: D

Correct answer: No error

There is no error. %.#s and %2s are not the specifiers the author probably intended, but printf is not obliged to reject them - the format string is parsed at run time, and undefined or unrecognised conversions do not stop the program compiling. The array declaration is perfectly ordinary.

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

Post your comment

Please log in or register to post a comment.