-
What will be the output of the following C code?
#include <stdio.h>
int main()
{
if (printf("%d", printf(")))
printf("I am Sad...");
else if (printf("1"))
printf("I am Happy...");
}
-
- Runtime Error
- I am Sad...
- I am Happy...
- Compilation Error
- None of these
Correct Option: D
Compilation Error
main.c: In function ‘main’:
main.c:4:33: warning: missing terminating " character
if (printf("%d", printf(")))
^
main.c:4:33: error: missing terminating " character
if (printf("%d", printf(")))
^~~~
main.c:5:35: error: expected ‘)’ before ‘;’ token
printf("We are Happy");
^
main.c:5:13: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
printf("We are Happy");
^~~~~~
In file included from main.c:1:0:
/usr/include/stdio.h:365:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
extern int printf (const char *__restrict __format, ...);
^~~~~~
main.c:8:5: error: expected ‘)’ before ‘}’ token
}
^
main.c:8:5: error: expected ‘)’ before ‘}’ token
main.c:8:5: error: expected expression before ‘}’ token