printf/scanf and return value

We know that printf and scanf functions are used to print a value and scan a value respectively
but most of the people don’t know the return values of them.For example:int main() {
int n;
printf(“%d”,scanf(“%d”,&n));
return 0;
}Then what will be output?output: 1Because scanf will return the total number of input successfully scan.
This will more clear when we will take another exampleint main() {
int n;
printf(“%d”,scanf(“%d %d”,&n,&n));
return 0;
}

Output: 2Printf function returns total number of characters printedint main() {
int n;
printf(“%d”,printf(“%d”,100));
return 0;
}

Output: 3Because 100 has 3 char ‘1’ ‘0’ ‘0’Now we can think in another way likeint main() {
int n=4;
printf(“scanf(“%d %d”,&n,&n)”);
return 0;
}what will be the output in this case?It will be an error because it breaks the printf rule
%d %d are out of double quotes, first quotes have “scanf(” and second have “,&n,&n”But if we will do it in some other manner like belowint main() {
int n=4;
printf(“scanf(“%d %d””

News Reporter

Leave a Reply

Your email address will not be published. Required fields are marked *