Chapter - 4: The Loop Control Structure

What would be the output of the following programs:


C
Sections
1
Exercises

A

B

C

D

E

1

(a)

#include<stdio.h>
int main()
{
	int i = 0 ;
	for ( ; i ; ) 
		printf ( "\nHere is some mail for you" ) ; 
	return 0;
}

Output: Nothing, just blank screen.


(b)

#include<stdio.h>
int main()
{
	int i ;
	for ( i = 1 ; i <= 5 ; printf ( "\n%d", i ) ) ;
		i++ ; 
	return 0;
}

Output: 1 (infinite times.)


(c)

#include<stdio.h>
int main()
{
	int i = 1, j = 1 ;
	for ( ; ; )
	{
		if ( i > 5 )
			break ;
		else
			j += i ;
		printf ( "\n%d", j ) ;
		i += j ;
	} 
	return 0;
}

Output:
2
5


© 2020 Garbage Valuegarbage value logo