a The initial statement is executed only once b The second condi tion is

A the initial statement is executed only once b the

This preview shows page 38 - 42 out of 111 pages.

a) The initial statement is executed only once. b) The second condi-tion is printed before '*' is printed. The second statement also has short circuiting logical && operator which prints the second part only if 'i' is smaller than 2 b) The third statement is printed after '*' is printed. This also has short circuiting logical && operator which prints the second part only if '++i' is not zero. 9.Predict the output. (L3) #include<stdio.h> int main () { int fun = { printf ("C for loop ") }; int x = 5; for (x=0; x<=fun; x++) { Printf ("%x ", x); } return 0; } Answer:C for loop0 1 2 3 4 5 6 7 8 9 A Explanation: for loop executes first. for(x=0;x<=fun;x++) i.e.) for(x=0; x=printf("C for loop"); x++) Now printf in conditional place of for loop prints C for loop and the count in that string is replace in conditional place of for loop i.e.) for(x=0; x<=10;x++) Thus the output is :C for loop 0 1 2 3 4 5 6 7 8 9 A Here A represent 10 in hexadecimal.
Background image
39 | P a g e 10. Predict the output of the code. (L3) #include <stdio.h> void main () { char cnt=0; for(;cnt++;printf("%d",cnt)) ; printf("%d",cnt); } Before entering into the for loop the CHECK CONDITION is "evalu-ated". Here it evaluates to 0 (false) and comes out of the loop, and i is incremented (note the semicolon after the for loop).
Background image
40 | P a g e WHILE LOOP VIVA QUESTIONS: 1. While loop is a ………………statement. (L1) Ans:Repetition 2. Write the syntax for while loop. (L1) Ans: while(condition) { //statements } 3. While loop is an_________ controlled loop? Ans: Entry 4.While loop checks the condition first and the loop keeps on running till the condition is true, it stops when the con-dition becomes false. (True/False) (L1)Ans: True5. Which loop is faster in C Language, for, while or Do While.? (L1) Ans: All loop work at same speed 6. Why while loop is preferred over for loop? (L2) Ans: For loopsare meant for structure of a fixed size like an array. They are useful when you need to do an operation a fixed number of times. While loops, in the other hand, are more dynamic, and you usually use them for lists or until a certain expression meets a criteria.
Background image
41 | P a g e 7. While loop can be expressed as ………loop + ……….Statement. (L2) Ans:for , if 8. How do you stop a while loop? (L2) Ans :A while loopcan also terminate when a break, goto, or return within the statement body is executed. The termination condition is evaluated at the top of the loop. 9. What is a loop control Variable and is it necessary in a while loop? (L3) Ans:The variablecount is initialized, tested, and changed as the loopexecutes. These variables are used in the loop condi-tion to terminate the loop. While loop doesn’talways need a loop control variable, instead break or go to can also be used. 10. What is a null loop? And give the syntax in while loop. (L3) Ans:Putting the semicolon directly after the for loop(and us-ing no braces) creates a null loopliterally, a loopthat contains no programming statements.
Background image
Image of page 42

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture