0
Please tell the output?? Ignore any syntax error
Main() { int a,b; clrscr(); a=b=1; while (a) { a=b++ <=3 Printf ("%d %d ", a,b); } Printf("\n %d %d", a+10, b+10); }
9 Answers
+ 4
SYNTAX CORRECTED:
# include<stdio.h>
int main() {
int a,b;
clrscr();
a = b = 1;
while (a) {
a = b++ < 3;
printf("%d %d", a, b);
}
printf("/n %d %d", a+10, b+10);
}
// Output:
1 2 1 3 1 4 0 5 10 15
I think may be m wrong.
I use to learn C , C++ but i left at middle and move to python.
+ 1
It is correct can u explain a bit
+ 1
Well,
a = b = 1 // here a and b value is set to 1
while (a) // If the test expression is true, statements inside the body ofĀ whileĀ loop are executed. Then, the test expression is evaluated again.
The process goes on until the test expression is evaluated to false.
If the test expression is false, the loop terminates (ends).
a = b++ < 3; // b++ here the value of b will increase by 1.
and continues till < 3;
%d - decimal format specifier
I'm not good at explaining as english is a bit hard for me.
+ 1
"\n"
opps and there in second print statement '\n' is used so 10 15 will be printed next line.
+ 1
hmm..Second print statement is outside while loop block.
+ 1
Ok thnk u so much
0
b should continue till < 3 but we have 4 and 5 in output also
0
And how does the value of a decremented to zero from 1 in output??
0
First it will complete the while loop after while the value we get it will add on a and b automatically,Simple