0% found this document useful (0 votes)
36 views11 pages

Unit-2 Questions

.

Uploaded by

sanjaynova2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views11 pages

Unit-2 Questions

.

Uploaded by

sanjaynova2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

UNIT-II

1 Marks

1 1. Which of the following is a sequential operator?

a) +

b) ==

c) &&

d) ++

Answer: a) +

2. What is the result of the expression 5 > 3 && 4 < 6?

a) True

b) False

c) Error

d) None of the above

Answer: a) True

3. Which of the following expressions will evaluate to true if y is


7?

a)if (y && 7)

b)if (y != 7)

c) if (y == 7)

d)if (y > 7)

Answer: c) if (y == 7)

4. Which operator is used for incrementing a variable by 1 in C?

a)--
b)++

c)+=

d)+

Answer: b)++

5. what will happen if a is 5 and b is 3?

int a = 5, b = 3;

if (a > 2 && b < 2)

printf("Condition 1");

else if (a == 5 || b == 3)

printf("Condition 2");

else

printf("Condition 3");

a)Condition1

b)Condition2

c)Condition 3

d)No output

Answer: b) Condition2
Which operator is used to perform a bitwise OR operation?

6. a) |

b) ||

c) &

d) &&

Answer: a) |

7. What does the expression a >>= 1 do?

a) Divides a by 2

b) Multiplies a by 2

c) Adds 1 to a

d) Shifts the bits of a to the right by 1

Answer: d) Shifts the bits of a to the right by 1

1.

8. Which of the following is true about the switch statement?

a) It can handle floating-point expressions.

b) It only works with integer and character expressions.

c) It can compare strings.

d) It is identical to the if-else structure.

Answer: b) It only works with integer and character


expressions.
9. What will be the output of the following C code?

int a = 10;

while(a > 5) {

printf("%d ", a);

a--;

1.10 9 8 7 6 5

2. 10 9 8 7 6

3. 9 8 7 6 5

4. Infinite loop

Answer: 2. 10 9 8 7 6

10. Which looping construct is best when the number of

Iterations is known beforehand?

1.while loop

2.do-while loop

3.for loop

4.All are equally good

Answer: 3.for loop


11 In a for loop, which part is executed only once?

a) Initialization

b) Condition

c) Update

d) All parts are executed multiple times

Answer: a) Initialization

12 How many times will the loop run in the following code?

for (int i = 0; i < 5; i++)

printf("%d", i);

}
a) 4 times
b) 5 times
c) Infinite loop
d) It won’t run

Answer: b) 5 times
13 What is the output of the following code?

int main() {

int x = 5;

printf("%d %d", x++, ++x);

return 0;

A. 5 7

B. 6 7

C. 6 6

D. 7 7

Answer: A. 5 7

14 Which of the following is not a valid data type in C?

A. float

B. integer

C. char

D. string

Answer: D. string
15 What is the purpose of the #include directive in C?

A. To declare variables

B. To define functions

C. To include header files

D. To print output to the console

Answer: C. To include header files

16 What is the output of the following code?

int x = 10;

if (x++ == 10)

printf("x is 10");

} else {

printf("x is not 10");

A. x is 10

B. x is not 10

C. The code will result in an error

D. The output will depend on the compiler

Answer: A. x is 10
17 What is the purpose of the break statement in a loop?

A. To continue to the next iteration of the loop

B. To exit the loop immediately

C. To declare a variable

D. To define a function

Answer: B. To exit the loop immediately

18 What is the purpose of the continue statement in a loop?

A. To continue to the next iteration of the loop

B. To exit the loop immediately

C. To declare a variable

D. To define a function

Answer: A. To continue to the next iteration of the loop

19 What is the output of the following code?

int i = 0;

while (i < 5) {

printf("%d ", i++);

A. 0 1 2 3 4

B. 0 1 2 3 4 5

C. 1 2 3 4 5

D. 0 1 2 3

Answer: A. 0 1 2 3 4
20 Which operator has the lowest precedence

A.sizeof

B.unary

C.assignment

D.comma

Answer: D.comma

2marks

1. Analyze Increment and Decrement Operators with an example.

2. Explain with example about goto statement.Why is it not


recommended?

3. Explain the difference between Pre-increment and Post-increment


operators

4. Write a C program to print odd numbers from 1 to 10

5. Explain about nested loop with example

6 Write a C expression to find the maximum of three numbers a, b, and c


using an if-else statement.

7 Write a C program snippet to generate a multiplication table for a


number using a for loop.

8 How would you generate prime numbers up to a given limit in C?

9 Write a program to find the LCM (Least Common Multiple) of two


numbers in C.

10 Write a C program snippet to calculate Simple Interest.

11. What are arithmetic operators, and list any four examples.

12. Differentiate between relational operators and logical operators.


13. Differentiate between break and continue

14. Explain how the ternary operator works with an example

15. What is the primary difference between while and do..while statements
in C?

16. Explain how the left shift operator (<<) works with an example

17. Difference between Logical operator and Bitwise operator with


example.

18. Write the Order of Precedence of operators.

19. If int a=8,b=15,c=4 then what will the value of the given expression

2*((a%5)*(4+(b-3)/( c+2)))

20. Write a C program for GCD of two numbers.

10 marks

1. Write a C program that takes two integers as input and performs all
arithmetic operations (addition, subtraction, multiplication, division,
and modulus). Use proper operator precedence and explain the
output for different inputs.

2. Explain the various types of decision making and branching


statements in c

3. Write a C program that takes the total marks obtained by a student in


a subject (out of 100) and determines the corresponding grade based
on the following criteria:

i)Grade A: 90 to 100 ii)Grade B: 80 to 89iii)Grade C: 70 to 79


iv)Grade D: 60 to 69 v)Grade E: 50 to 59vi) Fail: Below 50
4. What is the purpose of looping statement? Explain the various types
of looping statements in C with suitable example?

5. Write a C program for the following:

(i).To find the area and circumference of a circle with radius r. (5)

(ii). To check whether a given year is leap or not. (5)

6. Enumerate the difference between “else-if ladder” and “switch-case”


statements with appropriate C programs.

7. Discuss the use of relational and logical operators in C. Write a C


program that takes two numbers as input and checks if both numbers
are positive, both are negative, or they have different signs. Use
appropriate relational and logical operators in the program.

8. Write a C program to convert Celsius to Fahrenhit. Use the formula


F=C * (9/5)+32 Where F is temperature in Fahrenheit,C is
temperature in Celsius. Get input from user for temperature in
Celsius.

9. Write a C program to display the following menu options

1-Shopping 2-Watch movie 3-Play Cricket 4-Listen to music, If the


user enters one of the above options,display what the user
entered.else display the options again.

10. Write a C program to calculate Compound Interest. Get the inputs


from user and display the output.

You might also like