8. What is the difference between while and do while?
Ans:
The difference between a "do ...while" loop and a "while {} " loop is
that the while loop tests its condition before execution of the
contents of the loop begins; the "do" loop tests its condition after it's been executed at least once. As noted above, if the test condition is false as the while loop is entered the block of code is never executed. If the test condition is false as the do while loop is entered the block of code is executed once. Since the condition is tested at the bottom of a do loop, its block of code is always executed at least once. |
Ex - 2: What is the output?
main()
{
int i=10,j=20;
j = i, j?(i,j)?i:j:j;
printf("%d %d",i,j);
}
Ans:
10 10
Explanation:
The Ternary operator ( ? : ) is equivalent for if-then-else statement. So the question can be written as:
if(i,j)
{
if(i,j)
j = i;
else
j = j;
}
else
j = j;
|