0% found this document useful (0 votes)
6 views4 pages

C Programming Questions and Answers

The document is a C programming quiz containing 30 questions with their respective answers. It covers various topics such as output of code snippets, data types, storage classes, memory allocation, and functions in C. Each question is followed by the correct answer, providing a quick reference for C programming concepts.

Uploaded by

Vishwa Hb
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)
6 views4 pages

C Programming Questions and Answers

The document is a C programming quiz containing 30 questions with their respective answers. It covers various topics such as output of code snippets, data types, storage classes, memory allocation, and functions in C. Each question is followed by the correct answer, providing a quick reference for C programming concepts.

Uploaded by

Vishwa Hb
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/ 4

C Programming Quiz - Questions and Answers

1. What is the output of the following?

int x = 10;

int y = 5;

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

Answer: C. 17

2. What is the size of the following union?

union test {

int x;

float y;

char z;

};

Answer: B. 4

3. Which of the following is not a storage class in C?

Answer: D. volatile

4. What is the default return type of the main function in C?

Answer: B. int

5. What is the output of the following code?

printf("%d", sizeof('A'));

Answer: C. 4

6. Which operator is used to access members of a structure using a pointer?

Answer: B. ->

7. What is the output of the following code?

int x = 3;
printf("%d", x << 1);

Answer: A. 6

8. Which header file is required for malloc() function?

Answer: A. stdlib.h

9. Which function is used to compare two strings in C?

Answer: A. strcmp()

10. What is the keyword to define a constant in C?

Answer: D. Both A and C

11. What will be the output?

int a = 5;

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

Answer: D. Undefined behavior

12. Which of the following data types has the highest precision?

Answer: B. double

13. Which loop is guaranteed to execute at least once?

Answer: C. do-while

14. Which function is used to find the length of a string?

Answer: A. strlen()

15. What does the following declaration mean?

int (*ptr)[10];

Answer: A. ptr is a pointer to an array of 10 integers

16. Which keyword is used to prevent changes to a variable in C?

Answer: A. const

17. How many bytes are occupied by an int in C (typically)?


Answer: B. 4

18. What is the output of the following?

printf("%c", 65);

Answer: A. A

19. Which function is used to dynamically allocate memory?

Answer: D. Both B and C

20. What is the correct format specifier for printing a float?

Answer: C. %f

21. What is the output of the following?

printf("%d", printf("%d", 1234));

Answer: A. 11234

22. enum colors { RED, BLUE, YELLOW };

printf("%d..%d..%d", RED, YELLOW, BLUE);

Answer: A. 0..2..1

23. #define Square(m) m*m

int i = 64 / Square(4);

Answer: B. 64

24. class TempClass { public: TempClass() { cout << "Inside constructor"; } };

Answer: C. Inside constructor

25. Point p1; p1.setX(10); p1.setY(20); Point p2 = p1; p2.print();

Answer: A. x = 10, y = 20

26. Derived obj; obj.Base::f();

Answer: A. Base

27. int x = 20; Test t1(x); x = 30;


Answer: C. 20 30

28. printf("\n12"); printf("\b34"); printf("\r56");

Answer: B. 1342

29. Point t1, *t2;

Answer: B. Constructor called

30. int x = 10; x = - (++x) - (x++);

Answer: D. Compiler error

You might also like