Top

Discussion

What is the output of this C code?

#include 
    int main()
    {
        printf("C programming %s", "Class by\n%s Sanfoundry", "WOW");
    }

 

  • A.C programming Class by WOW Sanfoundry
  • B.C programming Class by\n%s Sanfoundry
  • C.C programming Class by %s Sanfoundry
  • D.Compilation error

Answer: C

This program has only one %s within first double quotes, so it does not read the string “WOW”.
The %s along with the Sanfoundry is not read as a format modifier while new line character prints the new line.
Output:
$ cc pgm2.c
$ a.out
C programming Class by
%s Sanfoundry

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

Post your comment