Welcome Guest | Sign in | Register

Home > C Programming > Loops > Questions and Answers

01. Consider the following program,
main ()
{
int i, j;
for (i=0, j=5; j >0, i < 10; i ++, j--)
printf("lucentblackboard.com");
}
How many times " lucentblackboard.com " will get printed
A. 5 B. Compilation Error
C. 10 D. Compilation Error

Answer and Explanation

Answer: 10

Explanation:
Condition part of for loop ( j>0, i<10 ) is separated by commas which means that compiler will use the value which is at right hand side of comma i.e of i<10 so the loop will execute till the value of i is less than 10.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. How many times the below loop will get executed?
main()
{
int i;
for(i=9;i;i=i-2)
{
printf("\n%d",i);
}
}
A. 5 B. 6
C. Compilation Error D. Infinite

Answer and Explanation

Answer: Infinite

Explanation:
Above loop will iterate till i have non zero value. Initial value of i is 9 and it get decremented by 2 in every iteration ( 9, 7, 5, 3, 1, -1, -3 â?¦.). Value of i will never become 0 and loop will run infinitely.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03. How many times the below loop will get executed?
main()
{
int i;
for(i=20, i=10; i<=20; i++)
{
printf("\n %d", i);
}
}
A. 1 B. Run time Error
C. 11 D. Compilation Error

Answer and Explanation

Answer: 11

Explanation:
i will start from 10

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. How many times the below loop will get executed?
main()
{
int i,j;
i = 10;
for (j=i==10 ; j<=10 ; j++)
{
printf("\n%d",j);
}
}  
A. 1 B. 10
C. 11 D. Compilation Error

Answer and Explanation

Answer: 10

Explanation:
Expression i ==10 return 1 and j get initialized to 1.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. How many times the while loop will get executed?
main ( )
{
int a = 1 ;
while ( a <= 100) ;
{
printf ( "%d", a++ ) ;
}
}
A. 100 B. 1
C. 0 D. Infinite

Answer and Explanation

Answer: Infinite

Explanation:
Loop will execute infinite no of times because of the ; at the end while loop.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06. What is the output of the following code?
#include "stdio.h"
main()
{
int i;
for(i=0;i<5;i++)
{
static int a=0;
int b=0;
a++;
b++;
printf("%d %d",a,b);
}
return 0;
}
A. 1 1 2 1 3 1 4 1 4 1 B. 1 1 2 1 3 1 4 1 5 1
C. 1 0 2 0 3 1 4 1 5 1 D. 0 1 2 0 3 1 4 1 5 1

Answer and Explanation

Answer: 1 1 2 1 3 1 4 1 5 1

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
07. What is the output of following program?
void main(){
int a;
a=1;
while(a-->=1)
while(a-->=0);
printf("%d",a);

A. 3 B. -3
C. 0 D. error

Answer and Explanation

Answer: -3

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
08. How many times the while loop will get executed?
main ( )
{
int a = 1 ;
while ( a <= 100) ;
{
printf ( â??%dâ??, a++ ) ;
}
}
A. 100 B. 1
C. 0 D. Infinite

Answer and Explanation

Answer: Infinite

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
09. What is the output of the following program?
void main(){
int a;
a=10;
while(a++<=15)
printf("%d",a);
printf("%d",a+10);
}
A. 10 11 12 13 14 15 16 B. 11 12 13 14 15 16 27
C. 10 11 12 13 14 15 25 D. 11 11 12 13 14 15 25

Answer and Explanation

Answer: 11 12 13 14 15 16 27

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
10. What is the output of the following program?
void main(){
int a,b;
a=b=10;
while(a)
{
a=b++<=13;
printf("%d%d",a,b);
}
printf("%d%d",a+10,b+10);

A. 1 11 1 12 1 13 1 14 0 15 a=10 b=25 B. 1 11 1 12 1 13 1 14 0 15 a=10 b=25
C. 1 11 1 12 1 13 1 14 0 15 a=11 b=25 D. 0 11 1 12 1 13 1 14 0 15 a=10 b=25

Answer and Explanation

Answer: 1 11 1 12 1 13 1 14 0 15 a=10 b=25

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.