Bansal Institute of Science and Technology Bhopal
Unit -3 Praticse Set
Subject -C programming part-I
1. What is the output of following If-else program
#include<stdio.h>
int main()
{
int m=0;
if(m==0)
{
m=((5,(m=3)),m=1);
printf("%d",m);
}
else
printf("Test");
a. Test
b. 1
c. 3
d.5
Ans- B
2. What is the output of following If-else program
#include<stdio.h>
int main()
{
int a=5,b=2,c=1;
if(b>a && a>c && c>b)
b=a+1;
else
a=b+1;
printf("%d",a+b+c);
a. 6
b. 11
c. 19
d.7
Ans- A
--------------------------------------------------------------------------------
3. What is the output of following Conditional program ?
#include<stdio.h>
int main()
{
int x=2,y=0,z=3;
x>y ?( printf("%d", z)):( return z);
a. 2
b. 3
c. 11
d.Error
Ans-b
------------------------------------------------------------------------------------------------------
4. What is the output of following program
#include<stdio.h>
int main(){
float x = 0.0;
long int y = 10;
printf("%d", sizeof(y) == sizeof(x+y));
return 0;
}
a. 1
(b. 0)
c4
d8
Ans-B
5. What is the output of following program
#include<stdio.h>
int main(){
int p = 9, w = 6;
p=p+1;
w=w-1;
p=p+w;
if (p > w)
{
printf ("p");
}
else
{
printf ("w");
}
a)p
b) w
c) Error
d) None of these
Ans-a
6. Which is not a bitwise operator?
1. &
2. |
3. <<
4. (&&)
Ans- 4
-----------------------------------------------------------------------------------------------------------------------
7. Left shift (<<) and Right shift (>>) operators are equivalent to _____________ by
Choose the correct words...
1. (Multiplication and Division)
2. Division and Multiplication
3. Multiplication and Remainder
4. Remainder and Multiplication
Ans- 1
--------------------------------------------------------------------------------------------------------------------
8. what is the output of following code?
#include <stdio.h>
int main()
{
int a = 2;
if (a=a+1)
printf("%d\n", a);
}
A. 0
B. 1
C. 3
D. No output
Ans- C
9. what is the output of following code?
#include <stdio.h>
int main()
{
int a = 2;
if (a >> 1)
printf("%d\n", a);
}
a) 0
b) 1
c) 2
d) No Output
Ans- C
10. what is the output of following code?
#include <stdio.h>
void main()
{
int x = 97;
int y = sizeof(x++);
printf("x is %d", x);
}
a) x is 97
b) x is 98
c) x is 99
d) Run time error
Ans- a
11.what is the output of following code?
#include <stdio.h>
void main()
{
int a = 5, b = -7, c = 0, d;
d = ++a && ++b || ++c;
printf("\n%d%d%d%d", a, b, c, d);
}
a) 6 -6 0 0
b) 6 -5 0 1
c) -6 -6 0 1
d) 6 -6 0 1
Ans- d
12.what is the output of following code?
#include <stdio.h>
int main()
{
int x = 2;
x = x << 1;
printf("%d\n", x);
}
a. 4
b) 1
c) 2
d) None
Ans- a
13.what is the output of following code?
#include <stdio.h>
int main()
{
int x = -2;
if (!0 == 1)
printf("yes\n");
else
printf("no\n");
}
a)yes
b) no
c) run time error
d) undefined
Ans- a
----------------------------------------------------------------------------------------
14. what is the output of following code?
#include <stdio.h>
int main()
{
unsigned int a = 10;
a = ~a;
printf("%d\n", a);
}
a)-9
b) -10
c) -11
d) 10
Ans- b
-----------------------------------------------------------------------------------
15. What is the output of following Conditional program ?
#include<stdio.h>
int main()
int a=0;
a = 5>2 ? printf("4"): 3;
printf("%d",a);
}
A)4
B) 3
C)41
D) Error
Ans- C
16.Which bitwise operator is suitable for turning off a particular bit in a number?
a) && operator
b) & operator
c) || operator
d) ! operator
Ans- b
--------------------------------------------------------------------------------------------------------------------
17. Choose a statement to use C If Else statement
A) else if is compulsory to use with if statement
B) else is compulsory to use with if statement
C) else or else if is optional with if statement
D) None of the above
Ans- C
18. What will be the output of the following C code?
#include<stdio.h>
int main()
{
int k = 0;
for (k < 3; k++)
printf("Hello");
a) Compile time error
b) Hello is printed thrice
c) Nothing
d) Varies
Ans-A
Q 19. What will be the output of the following C code
#include
<stdio.h> void
main()
double k = 0;
for (k = 0.0; k < 3.0;
k++)
printf("Hello");
A) Run time error
B) Hello is printed thrice
C) Hello is printed twice
D) Hello is printed infinitely
Ans-B
Q 20. What will be the output of the following C
code? #include <stdio.h>
void main()
{
int k =
0; for
(k)
printf("Hello");
a) Compile time error
b) hello
c) Nothing
d) Varies
Ans-A
Q 21. Loops in C Language are implemented using.?
A) While Block
B) For Block
C) Do While Block
D) All the above
Ans-D
Q 22. What is the output of C Program.?
#include <stdio.h>
int main()
{
int a=5;
while(a=5)
{
printf("RABBIT\
n"); break;
}
printf("GREEN");
return 0;
}
A)GREEN
B)RABBIT
GREEN
C) RABBIT is printed unlimited number of times.
D) Compiler error.
Ans-B
Q 23. What is the output of the given below
program? #include<stdio.h>
int main()
{
int i =
0; for
(i)
{
printf("Hello");
}
return 0;
}
A) Know Program
B) Know Program is printed infinite times.
C) Compiled Successfully, No Output
D) Compile-time error
Ans-D
Q24) What is the output of the given below program?
#include<stdio.h>
int main()
{
int i;
for (i=0; i<3; i++);
{
printf("%d", i);
}
return 0;
}
A) 0123
B) 01234
C) 4
D) 3
Ans-D
Q 25) What is output of the below program?
#include<stdio.h>
int main()
{
int i,j;
for(i = 0,j=0;i<5;i++)
{
printf("%d%d--",i,j);
}
return 0;
}
A)0--01--12--23--34--
(B) 00--10--20--30--40--
(C) Compilation Error
(D) 00--01--02--03--
04—
Ans- B
Hint-In this code only i is incrementing starting from 0 to 4 but j is 0 only.
Q 26 )What is output of program?
#include<stdio.h>
int main()
{
for(; ;);
for(; ;);
printf("Hello
"); return 0;
A)Compilation Error
(B) Runtime Error
(C) Nothing is printed
(D) Hello is printed infinite times
Ans-C
Hint:-blank for loop with ; ; is always infinite loop. printf() will never executed in this
program.
27 ) What is the output of the following code?
#include<stdio.h>
int i = 0;
for (i = 0; i< 5; i+))
printf("%d
", i); if (i ==
3)
break;
A) 0 1 2 3
B) 0 1 2 3 4
C) 0 1 2 3 4 5
D) None of the
above
Ans-B
28). Which keyword is used to come out of a loop only for single iteration?
a) break
b) continue
c) return
d) none of the
mentioned Ans-B
-------------------------------------------------------------------------------------------------
29)Predict output of following C
program: #include <stdio.h>
int main()
{
int i = 0;
for ( ; i<5 ; i++)
printf("%d
", i);
return 0;
}
A. 0 1 2 3 4
B. 1 2 3 4 5
C. Compile time error
D. none of these
Ans-A
30)Predict output of following C program
#include
<stdio.h> int
main()
{
int i;
for (i=65; i<70;
i++)
printf("%c ",
i);
return 0;
}
A. 65 66 67 68 69
B. A B C D E
C. Compile time error
D. Run time
error Ans-B
------------------------------------------------------------------------------------------------------------------
31)Which control structure is used to repeatedly execute a block of code in C?
A. for loop
B. if statement
C. switch case
D. while loop
Answer: Option D
-------------------------------------------------------------------------------------------------------------
32)How many times will a 'do-while' loop execute its body if the condition is initially false in C?
A. 0 times
B. 1 time
C. Infinite times
D. It depends on the loop body
Answer: Option B
----------------------------------------------------------------------------------------------------------------------
------
33)What will be the output of the following
C code?
#include <stdio.h>
Int main()
{
int i = 0;
do
{
i++;
if (i ==2)
countinue;
printf("In while loop ");
}
while (i< 2);
printf("%d\n"
, i);
}
A. In while loop 2
B. In while loop in while loop 3
C. In while loop 3
D. Infinite loop
Answer: Option A
34.
a)26
b) 25
c) 24
d) 23
Ans-C
35.
A) *a*1*2*3*4*5
B) *0*1*2***
C) *0*1*2*
D) *0*1*2*3*
Ans- C
------------------------------------------------------------------------------------------------------------------------
----------------------------