C Programming - Declarations and Initializations - Discussion
Discussion Forum : Declarations and Initializations - Find Output of Program (Q.No. 11)
11.
In the following program how long will the for loop get executed?
#include<stdio.h>
int main()
{
int i=5;
for(;scanf("%s", &i); printf("%d\n", i));
return 0;
}
Answer: Option
Explanation:
During the for loop execution scanf() ask input and then printf() prints that given input. This process will be continued repeatedly because, scanf() returns the number of input given, the condition is always true(user gives a input means it reurns '1').
Hence this for loop would get executed infinite times.
Discussion:
49 comments Page 4 of 5.
Sachin said:
1 decade ago
Hi all,
The loop will execute only once because it is terminated by using ';' symbol.
The loop will execute only once because it is terminated by using ';' symbol.
Rakesh said:
8 years ago
No, It will not execute. In scanf statement, they put %s for int. It's an error.
Keerthana said:
1 decade ago
Here i is an integer but is scanned as a string. Will it not result in error?
Sandip said:
1 decade ago
Here for loop end with (;)
Is it correct syntax ?
please any body help me...
Is it correct syntax ?
please any body help me...
Satti said:
1 decade ago
Before initialization how a loop start with semicolon. Obviously wrong ?
Priyanka said:
1 decade ago
The for loop ends with a semi-colon, so how can it run infinte times?
Anommi said:
7 years ago
Becoz the scanf gets the value from the user and printf prints it.
Gayathri said:
2 decades ago
In this program if it returns one means what would be the answer?
Bala Ramya said:
9 years ago
Here, why they used %s for integer type. Will anyone explain it?
Charanjeet Singh said:
4 years ago
How String(%d) value stored in integer(&i)? Please explain.
(4)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers