0% found this document useful (0 votes)
240 views47 pages

3 The Loop Control Structure Final

The document discusses various loop control structures in C programming, including for, while, do-while loops as well as break, continue, goto and switch statements. It provides examples of each structure and explains their syntax and usage. Key topics covered include initializing and testing conditions for for and while loops, ensuring at least one iteration for do-while loops, breaking or continuing loop execution, and selecting between code blocks for different cases in switch statements.

Uploaded by

manish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
240 views47 pages

3 The Loop Control Structure Final

The document discusses various loop control structures in C programming, including for, while, do-while loops as well as break, continue, goto and switch statements. It provides examples of each structure and explains their syntax and usage. Key topics covered include initializing and testing conditions for for and while loops, ensuring at least one iteration for do-while loops, breaking or continuing loop execution, and selecting between code blocks for different cases in switch statements.

Uploaded by

manish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 47

The Loop Control Structure in C

By Anurag Malik
CS&E

12/15/2019 1
The Loop Control Structure - C
Programming
• Sometimes we want some part of our code to be
executed more than once. We can either repeat
the code in our program or use loops instead. It is
obvious that if for example we need to execute
some part of code for a hundred times it is not
practical to repeat the code. Alternatively we can
use our repeating code inside a loop.
• There are three methods
– for,
– while
– do-while

12/15/2019 2
while loop
• While loop is constructed of a condition or
expression and a single command or a block of
commands that must run in a loop.
• //for single statement
• while(expression)
• statement;
• //for multiple statement
• while(expression)
• { block of statement }

12/15/2019 3
Whats The Output
• #include <stdio.h>
• int main ()
• int a = 10; { /* local variable definition */
• while( a < 15 )/* while loop execution */
• { printf("value of a: %d\n", a);
• a++; }
• return 0;
• }
• When the above code is compiled and executed, it produces
the following result −
• value of a: 10
• value of a: 11
• value of a: 12
• value of a: 13
• Value of a: 14
12/15/2019 4
for loop
• for loop is something similar to while loop but it is more complex. for loop is
constructed from a control statement that determines how many times the
loop will run and a command section. Command section is either a single
command or a block of commands.
• //for single statement
• for(control statement) statement;
• //for multiple statement
• for(control statement) { block of statement }
• Control statement itself has three parts:
• for ( initialization; test condition; run every time command ) Initialization part is
performed only once at for loop start. We can initialize a loop variable here.
• Test condition is the most important part of the loop. Loop will continue to
run if this condition is valid (true). If the condition becomes invalid (false)
then the loop will terminate.
• Run every time command section will be performed in every loop cycle. We
use this part to reach the final condition for terminating the loop. For
example we can increase or decrease loop variable’s value in a way that
after specified number of cycles the loop condition becomes invalid
12/15/2019 5
and for loop can terminate.
Example
• #include <stdio.h>
• int main ()
• { int a;
• /* for loop execution */ for( a = 10; a < 15; a = a + 1 )
• { printf("value of a: %d\n", a); }
• return 0;
• }
• When the above code is compiled and executed, it produces the
following result −
• value of a: 10
• value of a: 11
• value of a: 12
• value of a: 13
• value of a: 14

12/15/2019 6
do-while loop
• The while and for loops test the termination condition at
the top. By contrast, the third loop in C, the do-while,
tests at the bottom after making each pass through the
loop body; the body is always executed at least once.
• The syntax of the do is
• do { statements; }while (expression);
• The statement is executed, then expression is evaluated.
If it is true, statement is evaluated again, and so on.
When the expression becomes false, the loop
terminates. Experience shows that do-while is much less
used than while and for. A do-while loop is used to
ensure that the statements within the loop are executed
at least once.

12/15/2019 7
Example
• #include <stdio.h>
• int main ()
• { /* local variable definition */
• int a = 10;
• /* do loop execution */
• do {
• printf("value of a: %d\n", a);
• a = a + 1; }
• while( a < 15 );
• return 0;
• }
• When the above code is compiled and executed, it produces the following result −
• value of a: 10
• value of a: 11
• value of a: 12
• value of a: 13
•12/15/2019
value of a: 14 8
Break & Continue statement
• We used break statement in switch...case structures
previouslly.
• We can also use "break" statement inside loops to
terminate a loop and exit it (with a specific condition).
• while (num<20)
• { printf("Enter score : ");
• scanf("%d",&scores);
• if(scores<0) break; }
• Continue statement can be used in loops. Like break
command continue changes flow of a program. It does
not terminate the loop however. It just skips the rest of
current iteration of the loop and returns to starting
point of the loop.
12/15/2019 9
Example (break)
• #include <stdio.h>
• void main ()
• { int a = 10;
• while( a < 20 )
• { printf("value of a: %d\n", a);
• a++;
• if( a > 15) {
• /* terminate the loop using break statement */ break;
• }}}
• When the above code is compiled and executed, it produces the following
result −
• value of a: 10
• value of a: 11
• value of a: 12
• value of a: 13
• value of a: 14
• value of a: 15
12/15/2019 10
Example (continue)
• #include<stdio.h>
• main()
• { while((ch=getchar())!='\n')
• { if(ch=='.')
• continue;
• putchar(ch);
• }}
• In above example, program accepts all input but
omits the '.' character from it. The text will be
echoed as you enter it but the main output will be
printed after you press the enter key (which is
equal to inserting a "\n" character) is pressed. As
we told earlier this is because getchar() function is
a buffered input function.
12/15/2019 11
Goto and labels
• C provides the infinitely-abusable goto statement,
and labels to branch to. Formally, the goto statement is
never necessary, and in practice it is almost always easy to
write code without it.
• Nevertheless, there are a few situations where gotos may
find a place. The most common is to abandon processing in
some deeply nested structure, such as breaking out of two
or more loops at once. The break statement cannot be used
directly since it only exits from the innermost loop. Thus:
• for ( ... ) { for ( ... ) { ... if (disaster) { goto error; } } } ... error:
/* clean up the mess */ This organization is handy if the
error-handling code is non-trivial, and if errors can occur in
several places.
• A label has the same form as a variable name, and is
followed by a colon. It can be attached to any statement in
the same function as the goto. The scope of a label is the
entire function.
12/15/2019 12
Example
• #include <stdio.h>
• int main ()
• { int a = 10;
• /* do loop execution */ LOOP:do { if( a == 15)
• { /* skip the iteration */ a = a + 1;
• goto LOOP; }
• printf("value of a: %d\n", a);
• a++; }
• while( a < 17 );
• return 0; }
• When the above code is compiled and executed, it produces the following result −
• value of a: 10
• value of a: 11
• value of a: 12
• value of a: 13
• value of a: 14
• value of a: 16
• Note - By uses of goto, programs become unreliable, unreadable, and hard to debug. And
yet many programmers find goto seductive.
12/15/2019 13
The Switch Statement
• In C programming language, the switch statement is a type of
selection mechanism used to allow block code among many
alternatives.Simply, It changes the control flow of program
execution via multiple blocks.

• Switch Statement Rules


• A switch works with the char and int data types.
• It also works with enum types
• Switch expression/variable data type and case data type should be
matched.
• A switch block has many numbers of case statements, Each case
ends with a colon.
• Each case ends with a break statement. Else all case blocks will
execute until a break statement is reached.
• The switch exists When a break statement is reached,
• A switch block has only one number of default case statements, It
should end of the switch.
12/15/2019 14
The Switch Statement
• The default case block executed when none of the cases is true.
• No break is needed in the default case.
• Switch Statement Usage
• We can use switch statements alternative for an if..else ladder.
• The switch statement is often faster than nested if...else Ladder.
• Switch statement syntax is well structured and easy to
understand.
• Syntax:
• switch ( <expression> or <variable> )
• { case value1: //Block 1 Code Here break;
• case value2: //Block 1 Code Here break;
• ...
12/15/2019 15
• default: Code to execute for not match case break; }
Example Program For Switch
• #include<stdio.h>
• #include<conio.h>
• void main()
• { char ch;
• printf("Enter the Vowel (In Capital Letter):");
• scanf("%c",&ch);
• switch( ch )
• { case 'A' : printf( "Your Character Is A\n" ); break;
• case 'E' : printf( "Your Character Is E\n" ); break;
• case 'I' : printf( "Your Character Is I\n" ); break;
• case 'O' : printf( "Your Character Is O\n" ); break;
• case 'U' : printf( "Your Character Is U\n" ); break;
• default : printf( "Your Character is Not Vowel or Not a Capital Letter\n"); break; }
• getch(); }
• Sample Output:
• Enter the Vowel (In Capital Letter):A Your Character Is A
• Enter the Vowel (In Capital Letter):O Your Character Is O
• Enter the Vowel (In Capital Letter):h Your Character is Not Vowel. & Not a Capital Letter
12/15/2019 16
Whats The Output
• #include <stdio.h>
• void main()
• { int i = 0;
• switch (i)
• {
• case '0': printf("Geeks");
• break;
• case '1': printf("Quiz");
• break;
• default: printf("GeeksQuiz");
• }
• }

• (A) Geeks (B) Quiz (C) GeeksQuiz (D) Compile-time error


• Answer: (C)
• Explanation: At first look, the output of the program seems to be Geeks. But, the cases
are labeled with characters which gets converted to their ascii values 48(for 0) and
49(for 1). None of the cases is labeled with value 0. So, the control goes to the default
block and GeeksQuiz is printed.
12/15/2019 17
Whats The Output
• #include <stdio.h>
• void main()
• { int i = 3;
• switch (i)
• {
• case 0+1: printf("Geeks");
• break;
• case 1+2: printf("Quiz");
• break;
• default: printf("GeeksQuiz");
• }
• }
• What is the output of the above program?
• A) Geeks B) Quiz C) GeeksQuiz D) Compile-time
error
Answer: (B)
Explanation: Expression gets evaluated in cases. The control goes to the second case block
after evaluating 1+2 = 3 and Quiz is printed.
12/15/2019 18
Whats The Output
• #include <stdio.h>
• #define EVEN 0
• #define ODD 1
• Void main()
• { int i = 3;
• switch (i & 1)
• { case EVEN: printf("Even"); break;
• case ODD: printf("Odd"); break;
• default: printf("Default");
• }
• }

• (A) Even (B) Odd (C) Default (D) Compile-time error


• Answer: (B)
Explanation: The expression i & 1 returns 1 if the rightmost bit is set and returns 0
if the rightmost bit is not set. As all odd integers have their rightmost bit set, the
control goes to the block labeled ODD.
12/15/2019 19
Whats The Output
• #include <stdio.h>
• Void main()
• {
• int i;
• if (printf("0"))
• i = 3;
• else
• i = 5;
• printf("%d", i);
• }
• Predict the output of above program?
(A) 3 (B) 5 (C) 03 (D) 0

Answer: (C)
Explanation: The control first goes to the if statement where 0 is printed.
The printf(“0”) returns the number of characters being printed i.e. 1. The block
under if statement gets executed and i is initialized with 3.
12/15/2019 20
Whats The Output
• #include <stdio.h>
• int i;
• void main()
• {
• if (i);
• else
• printf("Ëlse");
• }
• What is correct about the above program?
(A) if block is executed. (B) else block is executed.
(C) It is unpredictable as i is not initialized. (D) Error: misplaced else

Answer: (B)
Explanation: Since i is defined globally, it is initialized with default value 0. The Else
block is executed as the expression within if evaluates to FALSE. Please note that
the empty block is equivalent to a semi-colon(;). So the statements if (i); and if (i)
{} are equivalent.
12/15/2019 21
Whats The Output
• #include <stdio.h>
• Void main()
• {
• int c = 5, no = 10;
• do {
• no /= c;
• } while(c--);
• printf ("%d\n", no);
• }

• (A) 1 (B) Runtime Error (C) 0 (D) Compiler Error

Answer: (B)

Explanation: There is a bug in the above program. It goes inside the do-while loop
for c = 0 also. So it fails during runtime.
12/15/2019 22
Whats The Output
• # include <stdio.h>
• Void main()
• { int i = 0;
• for (i=0; i<20; i++)
• { switch(i)
• {
• case 0: i += 5;
• case 1: i += 2;
• case 5: i += 5;
• default: i += 4;
• break;
• }
• printf("%d ", i);
• } }
• (A) 5 10 15 20 (B) 7 12 17 22 (C) 16 21 (D) Compiler Error
Answer: (C)
Explanation: Initially i = 0. Since case 0 is true i becomes 5, and since there is no break statement till last
statement of switch block, i becomes 16. Now in next iteration no case is true, so execution goes to default
and i becomes 21. In C, if one case is true switch block is executed until it finds break statement. If no 23
12/15/2019
break statement is present all cases are executed after the true case.
Whats The Output
• #include<stdio.h> *
• void main() 2nd
• { int i = 0; 3rd
• for (printf("1st\n"); i < 2 && printf("2nd\n"); (D) 1st
++i && printf("3rd\n")) 2nd
3rd
• { printf("*\n"); } } *
1st
(A) 1st 2nd
2nd 3rd
*
3rd Answer: (B)
2nd Explanation: It is just one by one execution of
* statements in for loop.
(B) 1st • a) The initial statement is executed only once.
2nd b) The second condition is printed before ‘*’ is
* printed. The second statement also has short
3rd circuiting logical && operator which prints the
2nd second part only if ‘i’ is smaller than 2
* b) The third statement is printed after ‘*’ is
3rd printed. This also has short circuiting logical &&
(C) 1st operator which prints the second part only if ‘++i’
2nd is not zero.
3rd

12/15/2019 24
Whats The Output
• #include <stdio.h>
• void main()
• {
• int i;
• for (i = 1; i != 10; i += 2)
• printf(" GeeksQuiz ");
• }
• (A) GeeksQuiz GeeksQuiz GeeksQuiz GeeksQuiz GeeksQuiz
(B) GeeksQuiz GeeksQuiz GeeksQuiz …. infinite times
(C) GeeksQuiz GeeksQuiz GeeksQuiz GeeksQuiz
(D) GeeksQuiz GeeksQuiz GeeksQuiz GeeksQuiz GeeksQuiz GeeksQuiz

• Answer: (B)
Explanation: The loop termination condition never becomes true and the loop
prints GeeksQuiz infinite times. In general, if a for or while statement uses a loop
counter, then it is safer to use a relational operator (such as <) to terminate the loop
than using an inequality operator (operator !=).

12/15/2019 25
Whats The Output
• char inchar = 'A';
• switch (inchar)
• {case 'A' :
• printf ("choice A \n") ;
• case 'B' :
• printf ("choice B ") ;
• case 'C' :
• case 'D' :
• case 'E' :
• default:
• printf ("No Choice") ;
• }
• (A) No choice (B) Choice A (C) Choice A Choice B No choice
(D) Program gives no output as it is erroneous

• Answer: (C)
Explanation: There is no break statement in case ‘A’. If a case is executed and it doesn’t
contain break, then all the subsequent cases are executed until a break statement is found.
That is why everything inside the switch is printed.
12/15/2019 26
Whats The Output
• #include <stdio.h>
• void main()
• {
• int i = 3;
• switch(i)
• { printf("Outside ");
• case 1: printf("Geeks");
• break;
• case 2: printf("Quiz");
• break;
• defau1t: printf("GeeksQuiz");
• } }
• (A) Outside GeeksQuiz (B) GeeksQuiz (C) Nothing gets printed

• Answer: (C)
Explanation: In a switch block, the control directly flows within the case labels(or dafault
label). So, statements which do not fall within these labels, Outside is not printed. Please take
a closer look at the default label. Its defau1t, not default which s interpreted by the compiler
as a label used for goto statements. Hence, nothing is printed in the above program.
12/15/2019 27
Whats The Output
• In the following program, X represents the Data Type of the variable check.
• #include <stdio.h>
• void main()
• { X check;
• switch (check)
• {
• // Some case labels
• }
• }

• Which of the following cannot represent X?


(A) int (B) char (C) enum (D) float

• Answer: (D)
Explanation: A switch expression can be int, char and enum. A float
variable/expression cannot be used inside switch.

12/15/2019 28
Whats The Output
• #include <stdio.h>
• Void main()
• { char check = 'a';
• switch (check)
• {
• case 'a' || 1: printf("Geeks ");

• case 'b' || 2: printf("Quiz ");
• break;
• default: printf("GeeksQuiz");
• }
• }
• (A) Geeks (B) Geeks Quiz (C) Geeks Quiz GeeksQuiz (D) Compile-time error

• Answer: (D)
Explanation: An expression gets evaluated in a case label. Both the cases used are
evaluated to 1(true). So compile-time error: duplicate case value is flashed as duplicated
12/15/2019 29
cases are not allowed.
Whats The Output
• #include <stdio.h>
• Void main()
• {
• int check = 20, arr[] = {10, 20, 30};
• switch (check)
• {
• case arr[0]: printf("Geeks ");
• case arr[1]: printf("Quiz ");
• case arr[2]: printf("GeeksQuiz");
• }
• }
• (A) Quiz (B) Quiz GeeksQuiz (C) GeeksQuiz (D) Compile-time error

• Answer: (D)
Explanation: The case labels must be constant inside switch block. Thats why
the compile-time error: case label does not reduce to an integer constant is
flashed.
12/15/2019 30
Whats The Output
• #include<stdio.h>
• Void main()
• { int i = -5;
• while (i <= 5)
• { if (i >= 0)
• break;
• else
• { i++;
• continue;
• }
• printf("GeeksQuiz");
• }
• }
• (A) 10 times (B) 5 times (C) Infinite times (D) 0 times
• Answer: (D)
Explanation: The loop keeps incrementing i while it is smaller than 0. When i becomes 0, the
loop breaks. So GeeksQuiz is not printed at all.

12/15/2019 31
Whats The Output
• #include <stdio.h>
• Void main()
• { int i = 3;
• while (i--)
• { int i = 100;
• i--;
• printf("%d ", i);
• }
• }
• (A) Infinite Loop (B) 99 99 99 (C) 99 98 97 (D) 2 2 2
• Answer: (B)
Explanation: Note that the i–- in the statement while(i-–) changes the i of main()
And i== just after declaration statement int i=100; changes local i of while loop.

12/15/2019 32
Whats The Output
• #include <stdio.h>
• void main()
• { int x = 3;
• if (x == 2); x = 0;
• if (x == 3) x++;
• else x += 2;
• printf("x = %d", x);
• }
• (A) x = 4 (B) x = 2 (C) Compiler Error (D) x = 0

• Answer: (B)
Explanation: Value of x would be 2. Note the semicolon after first if
statement. x becomes 0 after the first if statement. So control goes to else
part of second if else statement.

12/15/2019 33
Whats The Output
• main ()
{
int ones, twos, threes, others;
int c;
ones = twos = threes = others = 0;
while ((c = getchar ()) != EOF)
{
switch (c)
{
case '1': ++ones;
case '2': ++twos;
case '3': ++threes;
break;
default: ++others;
break;
}
}
printf ("%d %d", ones, others);
}
if the input is "1a1b1c" what is the output?
a. 13 b. c. 33 d. 31

12/15/2019 34
Whats The Output
• Give the output of the following program:
• #include < stdio.h >
• main()
• {int I=1;
• while (I < 5)
• {
• printf(“%d”, I);
• }
• }

• A. Print the value of I as 1 B. Warning for no return type for main ( )


• C. Infinite loop D. Prints the value of I as11111

Answer C
12/15/2019 35
Whats The Output
• What is the output of the following module
• sum=0;
• I=0;
• Do
• { sum+=I;
• I++;
• }while(I<=5);
• printf(“%d”, sum);
• A. 28 B. 10 C. 15 D. 21
• Answer C
12/15/2019 36
Whats The Output
• Which of the following statements are correct about the below C-
program?
• #include<stdio.h>
• Void main()
• {
• int x = 10, y = 100%90, i;
• for(i=1; i<10; i++)
• if(x != y);
• printf("x = %d y = %d\n", x, y);
• }
• 1 :The printf() function is called 10 times.
• 2 :The program will produce the output x = 10 y = 10
• 3 :The ; after the if(x!=y) will NOT produce an error.
• 4 :The program will not produce output.
• A.1 B.2, 3 C.3, 4 D. 4
• Answer: Option B

12/15/2019 37
Whats The Output
• #include<stdio.h>
• Void main()
• { char c=48;
• int i, mask=01;
• for(i=1; i<=5; i++)
• {
• printf("%c", c|mask);
• mask = mask<<1;
• }
• }
• A.12400 B.12480 `C.12500 D.12556
• Answer: Option B

12/15/2019 38

Whats The Output
Which of the following errors would be reported by the compiler on compiling the program
given below?
• #include<stdio.h>
• void main()
• { int a = 5;
• switch(a)
• {
• case 1:
• printf("First");
• case 2:
• printf("Second");
• case 3 + 2:
• printf("Third");
• case 5:
• printf("Final");
• break;
• }}
• A. There is no break statement in each case. B.Expression as in case 3 + 2 is not
allowed.
• C. Duplicate case case 5: D. No error will be reported.
12/15/2019 39
• Answer: Option C
Whats The Output
• Point out the error, if any in the program.
• #include<stdio.h>
• Void main()
• { int P = 10;
• switch(P)
• { case 10:
• printf("Case 1");
• case 20:
• printf("Case 2");
• break;
• case P:
• printf("Case 2");
• break;
• } }
• A. Error: No default value is specified B.Error: Constant expression required at line case P:
• C. Error: There is no break statement in each case. D. No error will be reported.
Answer: Option B
• Explanation:
• The compiler will report the error "Constant expression required" in the line case P: . Because, variable
names cannot be used with case statements.
• The case statements will accept only constant expression.

12/15/2019 40
Whats The Output
• How many times "IndiaBIX" is get printed?
• #include<stdio.h>
• void main()
• { int x;
• for(x=-1; x<=10; x++)
• {
• if(x < 5)
• continue;
• else
• break;
• printf("IndiaBIX");
• }
• }
• A. Infinite times B.11 times C.0 times D.10
times
• Answer: Option C

12/15/2019 41
Whats The Output
• What will be the output of the program, if a short int is 2 bytes wide?
• #include<stdio.h>
• Void main()
• { short int i = 0;
• for(i<=5 && i>=-1; ++i; i>0)
• printf("%u,", i);
• }
• A. 1 ... 65535 B Expression syntax error C No output D 0, 1, 2, 3, 4, 5

• Answer: Option A
• Explanation:
• for(i<=5 && i>=-1; ++i; i>0) so expression i<=5 && i>=-1 initializes for loop.
expression ++i is the loop condition. expression i>0 is the increment expression.
• In for( i <= 5 && i >= -1; ++i; i>0) expression i<=5 && i>=-1 evaluates to one.
• Loop condition always get evaluated to true. Also at this point it increases i by
one.
• An increment_expression i>0 has no effect on value of i.so for loop get executed
till the limit of integer (ie. 65535)

12/15/2019 42
Whats The Output
• Which of the following statements are correct about the below C-
program?
• #include<stdio.h>
• void main()
• { int x = 10, y = 100%90, i;
• for(i=1; i<10; i++)
• if(x != y);
• printf("x = %d y = %d\n", x, y);
• }
• 1 :The printf() function is called 10 times.
• 2 :The program will produce the output x = 10 y = 10
• 3 : The ; after the if(x!=y) will NOT produce an error.
• 4 :The program will not produce output.
• A.1 B.2, 3 C.3, 4 D.4
• Answer: Option B

12/15/2019 43
Whats The Output
• What is the output of this C code?
int main()
{
int a = 4, n, i, result = 0;
scanf("%d", n);
for (i = 0;i < n; i++)
result += a;
}
• A. Addition of a and n.
• B. Subtraction of a and n.
• C. Multiplication of a and n.
• D. Division of a and n.
• Answer: Option C
12/15/2019 44
Whats The Output

void main()
{
int i, n, a = 4;
scanf("%d", &n);
for (i = 0; i < n; i++)
a = a * 2;
}
• A. Logical Shift left
• B. No output
• C. Arithmetic Shift right
• D. bitwise exclusive OR
• Answer: Option B

12/15/2019 45
Whats The Output
• void main()
• { int i=1;
• while (i<=5)
• { printf("%d",i);
• if (i>2)
• goto here;
• i++;
• }}
• fun()
• { here:
• printf("PP");
• }
• Answer:
• Compiler error: Undefined label 'here' in function main
• Explanation:
• Labels have functions scope, in other words The scope of the labels is limited to
• functions . The label 'here' is available in function fun() Hence it is not visible in function
• main

12/15/2019 46
Whats The Output
• Void main()
• {int i=0;
• for(;i++;printf("%d",i)) ;
• printf("%d",i);
• }
• Answer: 1
• Explanation:
• before entering into the for loop the checking condition is
"evaluated". Here it evaluates to 0 (false) and comes out
of the loop, and i is incremented (note the semicolon after
• the for loop).

12/15/2019 47

You might also like