in Written Exam edited by
489 views
0 votes
0 votes
What will be printed by following statement : printf(“%d”,scanf(“%d”,&n));
in Written Exam edited by
489 views

2 Answers

2 votes
2 votes
Best answer
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
selected by
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 .

2 Comments

#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
0
@viv wrong quotes used - " is the correct one.
0
0
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true