0 votes 0 votes What will be printed by following statement : printf(“%d”,scanf(“%d”,&n)); Rajesh Pradhan asked Feb 22, 2016 edited Feb 22, 2016 by Rajesh Pradhan Rajesh Pradhan 483 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
Best answer 2 votes 2 votes Scanf returns the no of inputs scanned successfully (if format string does not match scan can fail) and printf returns no of characters printed on the screen , so here 1 is returned by scanf (provided we enter a valid integer) and hence 1 is printed on the screen radha gogia answered Feb 23, 2016 selected Feb 25, 2016 by Arjun radha gogia comment Share Follow See all 0 reply Please log in or register to add a comment.
3 votes 3 votes scanf() returns the number of variables initialized with a value , in this case it is 1 because it stores the value of 1 variable . Therefore scanf() functions returns 1 , which is printed by printf() . Therefore ans is 1 . Riya Roy(Arayana) answered Feb 22, 2016 Riya Roy(Arayana) comment Share Follow See all 2 Comments See all 2 2 Comments reply viv696 commented Feb 24, 2016 reply Follow Share #include <stdio.h> int main(void) { int n; printf(“%d”,scanf(“%d”,&n)); return 0; } prog.c: In function 'main': prog.c:5:4: error: stray '\223' in program printf(“%d”,scanf(“%d”,&n)); ^ prog.c:5:12: error: expected expression before '%' token printf(“%d”,scanf(“%d”,&n)); ^ prog.c:5:12: error: stray '\224' in program prog.c:5:12: error: stray '\223' in program prog.c:5:12: error: stray '\224' in program prog.c:4:9: warning: unused variable 'n' [-Wunused-variable] int n; ^ 0 votes 0 votes Arjun commented Feb 25, 2016 reply Follow Share @viv wrong quotes used - " is the correct one. 0 votes 0 votes Please log in or register to add a comment.