Font size
WorksheetsC conditional statements and loops
Total questions: 55
Worksheet time: 24mins
int sum=10;
for (int i=0;i<=10;i++) {
sum+=i;}
How often does the loop run?
(a)
int sum=10;
for (int i=0;i<10;i++) {
sum+=i;}
What is the result of sum after the loop?
(a)
int sum=10;
for (int i=0;i<10;i++) {
sum+=i;}
How often does the loop run?
(a)
Which type of loop is a for loop?
Pretest
Nontest
Midtest
Posttest
Which of the following is the correct format of a "for" loop?
for(int i = 0; i < 10; i++);
for[int i = 0; i < 10; i++];
for(int i = 0; i < 10; i++)
for[int i = 0; i < 10; i++]
What are the three parts of a for loop?
initialize; test; increment
test; initialize; increment
increment; test; initialize
Larry; Mo; Curly
int i=0;
while (i>0){
cout << "hello";
i++;}
How often does this run?
0
1
infinite
not sure
int i=1;
while (i>0){
cout << "hello";
i++;}
How often does this run?
0
1
infinite
not sure
int i=0;
do{
cout << "hello";
i++;}while (i<0);
How often does this run?
0
1
infinite
not sure
What is the error in the code shown?
avg was not initialized to 0.
avg= sum/i is not how to calculate average.
i does not exist outside of the for loop.
There is no error.
How many loops are there in C?
2
3
4
1
What is currect syntax of for loop?
for(initialization;condition; increment/decrement)
for(increment/decrement; initialization; condition)
for(initialization, condition, increment/decrement
None of These
The statement i++; is equivalent to
i = i + i;
i = i + 1;
i = i - 1;
i --;
What's wrong? for (int k = 2, k <=12, k++)
the increment should always be ++k
the variable must always be the letter i when using a for loop
there should be a semicolon at the end of the statement
the commas should be semicolons
If you want a user to enter exactly 20 values, which loop would be the best to use?
while
switch
do-while
for
What does <= mean?
less than
greater than
less than or equal to
greater than or equal to
Which of the following is NOT a comparison operator in C++ language?
>
<=
=
==
What will be the output of this code?
OK
KO
Depends on compiler
Depends on standard
What is the value of "z" in this code?
The value of z is 10
The value of z is 15
The value of z is 15.6
The value of z is 16
What is output of below program?
int main()
{
int i,j,count;
count=0;
for(i=0; i<5; i++)
{
count++;
}
printf("%d",count);
return 0;
}
5
4
1
0
Number of Keywords present in C Language are .?
32
34
62
64
What is the only function all C programs must contain?
start()
system()
main()
Program()
What is the output of C Program.?
int main()
{
int a;
for(a=25; a <= 27; a++)
{
printf("%d ", a);
}
return 0;
}
25 25 25
25 26 27
27 27 27
Compiler error
What is the result after execution of the following code if a is 10, b is 5, and c is 10?
if ((a > b) && (a <= c))
a = a + 1;
else
c = c+1;
a = 10, c = 10
a = 11, c = 10
a = 10, c = 11
a = 11, c = 11
In switch statement Case Labels must ends with --------
;
:
,
}
----------------- are used in C programming to manipulate the data at bit level
Logical operator
Bitwise operator
Additional operators
None of the above
Every C statement ends with ------------?
.
;
,
}
4. Name the one which is not a looping statement
for
while
do-while
if
The conditional operator are also known as
Relational operator
Binary operator
Ternary operator
Chary operator
What will be the output of following code- for(int i = 1; i < 5; i++ )
{
printf("%d",i);
}
13
135
1234
12345
Select different parts of "for" looping statement-
Initialization part
Condition Part
Update part
All of these
This loop starts counting down from 10
for(int i=10; i>0; i--)
int i = 10;
count=10;
for(int i=0; i>0; i--)
Statement lets you run code many times while a condition is true
When
Condition
for
Parentheses
What output is produced by the following segment of code:
for (int i = 0; i < 12; i++)
printf("%d ", i );
0 1 2 3 4 5 6 7 8 9 10 11 12
0 1 2 3 4 5
6 7 8 9 10 11
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9
Infinite Loop
What will be the output of the following C code?
#include <stdio.h>
void main()
{
int x = 5;
if (x < 1)
printf("hello");
if (x == 5)
printf("hi");
else
printf("no");
}
hi
hello
no
error
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x = 0;
if (x == 1)
if (x == 0)
printf("inside if\n");
else
printf("inside else if\n");
else
printf("inside else\n");
}
inside if
inside else if
inside else
compile time error
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x = 0;
if (x == 1)
if (x >= 0)
printf("true\n");
else
printf("false\n");
}
Depends on the compiler
No print statement
True
False
The switch statement takes a given integer value then seeks a matching value among a number of _______ statements.
break
case
switch
goto
How many loops are there in C
1
3
2
4
Which of the following is an exit control statement
for
while
do while
continue
The value of i after the execution of the following segment is
i = 2;
for( i=0; i>10; i=i+1);
1
2
0
11
The output of the following segment is
int k, n=20;
k=(n>5?(n<=10?100:200):500);
printf("%d",n);
100
200
300
20
C language developed at _____?
AT & T's Bell Laboratories of USA in 1972
AT & T's Bell Laboratories of USA in 1970
Sun Microsystems in 1973
Cambridge University in 1972
which is the only function all C programs must contain?
start()
sys()
main()
scanf()
Which of the following is not a correct variable type?
float
real
int
double
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int a = 1, b = 1, c;
c = a++ + b;
printf("%d, %d", a, b);
}
a=1, b=1
a=2, b=1
a=1, b=2
a=2, b=2
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = 0;
int j = i++ + i;
printf("%d\n", j);
}
0
1
2
compile time error
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int a = 1, b = 1;
switch (a)
{
case a*b:
printf("yes ");
case a-b:
printf("no\n");
break;
}
}
yes
no
yes no
compile time error
Library function pow() belongs to which header file?
math.h
square.h
stdio.h
conio.h
Is it possible to run program without main() function?
yes
no
may be
How many main() function we can have in our project?
1
2
no limit
depends on the program
int x = 10;
int main()
{
int x = 0;
printf("%d",x);
return 0;
}
10
0
compile error
undefined
What should be the output:
int main()
{
int a = 10/3;
printf("%d",a);
return 0;
}
3.33
3.0
3
0
#include "stdio.h"
int main()
{
int a = 10;
printf("%d", a);
int a = 20;
printf("%d",a);
return 0;
}
1020
1010
2020
Error: Redeclaration of a
