in Programming in C
1,306 views
0 votes
0 votes
WHAT IS THE OUTPUT OF THE FOLLOWING CODE?

 

printf("%d",printf("ABC"));

IS IT ABC3
in Programming in C
1.3k views

4 Comments

No,read the syntax of scanf(), it is

int scanf(const char *format, ...);

and it's first argument is of const char* type i.e scanf() expects 1st argument as of const char* and 1st argument provided is "ABC" which is of char* type though you should provide some format specifier like %s etc.

0
0
EOF is returned since there is a matching failure.
0
0

but %s also not giving correct output. why?

https://ideone.com/RAGKnS

1
1

1 Answer

3 votes
3 votes
Best answer
The return value of printf is the number of characters it printed.

printf("%d",printf("ABC"));

To execute the outer printf it needs to execute the inner printf to obtain the second parameter.

Hence output is ABC3
selected by

4 Comments

$\text{It will not print anything as we have not specified any format specifier}$
0
0
@!KARAN it prints return value of scanf
0
0
printf("%s",scanf("ABC"));
printf("%c",scanf("ABC"));

@srestha try this!!

0
0