1,842 views
1 votes
1 votes

#include "stdio.h"
int main()
{
    char arr[100];
    printf("%d", scanf("%s", arr));
    /* Suppose that input value given
        for above scanf is "GeeksQuiz" */
    return 1;
}

(A) 9
(B) 1
(C) 10
(D) 100

 which is true ? explain it .

3 Answers

Best answer
2 votes
2 votes

Here we have to understand what the functions printf() and scanf() returns..

1) printf() returns the number of characters that are printed..

2) scanf() unlike the printf() function returns the number of items which are inputted instead of number of characters..

 printf("%d", scanf("%s", arr));   

So here we are inputting only one item which is "arr"..So 

scanf("%s", arr)   returns 1 as the return value as number of items here is 1..So 1 will be printed by printf(). 

Hence B) should be the correct answer..

selected by
0 votes
0 votes
suppose the base address of arr is 1000...in   printf("%d", scanf("%s", arr)); scanf will take the input and printf is just calculating how many things are stored at address 1000....it does not matter what type of input you will enter the output will be 1 only because at any particular time you are going to store only one value at base address 1000 if you input  even '.' then also output will be 1

hence final output is 1 only.

Related questions

2 votes
2 votes
1 answer
1
rupamsardar asked Aug 30, 2023
488 views
#include <stdio.h int f(int x) { if(x%2==0) { return f(f(x-1)); } else return (x++); } int main() { printf("%d",f(12)); ret...
0 votes
0 votes
1 answer
2
SHWETAV SUMAN asked Oct 6, 2022
330 views
i have typed the following code but when i executed it the solution was not according to my expectation.unsigned short int y= -9; int iy=y; printf(“%d”,iy); solutio...
0 votes
0 votes
3 answers
3
ykrishnay asked May 30, 2022
1,063 views
int main(){extern int a = 20;printf("%d",a); }//why this gives error but followig code is not extern int a =20;int main(){printf("%d",a); } //why this happens that first ...
0 votes
0 votes
0 answers
4
ykrishnay asked May 20, 2022
384 views
What is stream in c programming ? as i read file io in c programming so thats where i read “stream” word so what stream means ? thank you