0% found this document useful (0 votes)
18 views

2.unit Bits

The document discusses C programming concepts like data types, operators, control flow statements, and loops. It provides examples of C code snippets and their expected output. Multiple choice questions are asked about the output of the code examples and C language concepts.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

2.unit Bits

The document discusses C programming concepts like data types, operators, control flow statements, and loops. It provides examples of C code snippets and their expected output. Multiple choice questions are asked about the output of the code examples and C language concepts.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

UNIT-2

1. What is the output of this C code?


int main()
{
int i = 5;
int l = i / -4;
int k = i % -4;
printf("%d %d\n", l, k);
return 0;
}
a) Compile time error b) -1 1 c) 1 -1 d) Run time error
Answer B
2. What is the output of this C code?
void main()
{
int x=7%4*3/2;
printf(“Value of x is %d”,x);
}
a) Value of x is 1 b) Value of x is 4 c) Value of x is 3 d) Compile time error
Answer B

3. What is the output of this C code?


void main()
{
int a = 5;
int b = ( a++)+(++a);
printf("Value of b is %d", b);
}
a) Value of b is 12 b) Value of b is 10 c) Value of b is 11 d) Undefined behavior
Answer A
4. The precedence of arithmetic operators is (from highest to lowest)?
a) %, *, /, +, - b) %, +, /, *, - c) +, -, %, *, / d) %, +, -, *, /

Answer A
5. Which of the following data type will throw an error on modulus operator (%)
a) Char b) short c) float d) int
Answer C
6. What is the output of this C code?
void main()
{
int a = 20,b=15,c=5,d;
d=a==(b+c);
printf("%d", d);
}
a) 1 b) 40 c) 10 d) 5
Answer A
7. What is the type of below assignment expression if x is of type float and y is of type int?
y=x+y;
a) Int b) double c) There is no type for assignment expression d) float
Answer A
8. For c=2 what will be the value of c after c<<=1
a) C=1 b)c=2 c) c=3 d) c=4
Answer D
9. What is the output of this C code?
void main()
{
int k=8;
int m=7;
int z=k<m?k=m:m++;
printf(“%d”,z);
}
a) Runtime error b) 7 c) 8 d) Depends on the compiler
b) Answer B
10. Which operator produces the 1’s complement of the given binary value

a) Logical AND b) Bitwise NOT c) Bitwise OR d) Logical OR


Answer B
11. What is the output of this C code?
main()
{
printf(“\n %.2f”,1234.1234);
}

Answer: 1234.12
12. What will be the output?
void main ( )
{
printf(“%d”,5<10 );
}
Answer: 1
13. The output of the below code is
#include<stdio.h>
void main()
{
int x=0;
if(x==0)
printf(“Hai\t”);
else
printf(“Hello\t”);
printf(“Welcome\t”);
}
Answer: Hai Hello
14. The output of the below code is
void main()
{
int x=5;
if(x<1);
printf(“Hello”);
}
Answer: Hello
15. The output of the below code is
void main()
{
int i;
for (i =1;i <=10; i++)
{
if (i==5)
{
break;
}
printf("Hi \n");
}
}
Answer: Hi is printed 4 times
16. The output of the below code is
void main()
{
int i = 0;
if (i == 0)
{
printf("Hello");
continue;
}
}

Answer: Compile time error


17. Data type of the controlling statement of a switch statement cannot be of type
Answer: float
18. The continue statement cannot be used with
Answer: switch
19. In a for loop of C program if the condition is missing
Answer: It is assumed to be present and taken to be true
20. What is the output of this C code?
Void main()
{
int i;
for(i=0;i<10;i++);
printf(“%d”,i);
} Answer: 10

You might also like