Debug School

Akanksha
Akanksha

Posted on

Top 30 C language Interview Questions with Answers

1. What does "sizeof" in C return?

A. The size of a variable in bytes
B. The value of a variable
C. The memory address of a variable
D. The data type of a variable
Answer: A

2. In C, how is a single-line comment denoted?

A. //
B. #
C. /* /
D. --
**Answer: A
*

3. Which of the following data types is not supported in C?

A. int
B. float
C. double
D. char*
Answer: D

4. What does the "scanf" function do in C?

A. Print text to the console
B. Read input from the console
C. Calculate mathematical expressions
D. Display error messages
Answer: B

5. How is a character constant defined in C?

A. "A"
B. 'A'
C. A
D. "A"
Answer: B

6. Which of the following operators is used to access the value stored in a pointer in C?

A. &
B. ***
C. ->
D. #
**Answer: B

7. What is the result of the expression 5 / 2 in C?

A. 2.5
B. 2
C. 3
D. 2.0
Answer: B

8. In C, which loop is used for executing a block of code as long as a condition is true?

A. for
B. while
C. do-while
D. if
Answer: B

9. What does the "strcmp" function in C do?

A. Compare two strings
B. Copy one string to another
C. Concatenate two strings
D. Find the length of a string
Answer: A

10. What is the maximum value that can be stored in an "unsigned int" in C?

A. 32767
B. 65535
C. 2147483647
D. 4294967295
Answer: D

11. Which keyword is used to declare a constant in C?

A. final
B. const
C. static
D. readonly
Answer: B

12. How do you define a function in C that takes no arguments and returns an integer?

A. int myFunction(void)
B. void myFunction(int)
C. int myFunction()
D. void myFunction()
Answer: A

13. What does the "break" statement do in C?

A. Exits the loop or switch statement
B. Continues to the next iteration of the loop
C. Skips the current function call
D. Jumps to a specific line in the code
Answer: A

14. Which header file should be included to use the "malloc" function in C?

A.
B.
C.
D.
Answer: A

15. What is the purpose of the "void" keyword in a C function declaration?

A. It indicates a function that takes no arguments.
B. It specifies the return type of the function.
C. It represents an empty string.
D. It is used to declare a variable.
Answer: B

16. Which of the following is not a valid C identifier?

A. _variable
B. 123var
C. VarName
D. var_name
Answer: B

17. What is the purpose of the "continue" statement in C?

A. It terminates the loop.
B. It skips the current iteration and continues with the next.
C. It returns a value from a function.
D. It jumps to a specific line in the code.
Answer: B

18. Which of the following functions is used to close a file in C?

A. fclose()
B. close()
C. file_close()
D. fclosefile()
Answer: A

19. What is the scope of a global variable in C?

A. It is only accessible within the function where it is declared.
B. It is accessible throughout the entire program.
C. It is accessible within a specific block of code.
D. It is not accessible outside of the file where it is declared.
Answer: B

20. In C, what is the purpose of the "++" operator?

A. It subtracts 1 from a variable.
B. It multiplies a variable by 2.
C. It increments a variable by 1.
D. It performs a logical OR operation.
Answer: C

21. Which function is used to print formatted text to the console in C?

A. print()
B. console.log()
C. printf()
D. display()
Answer: C

22. What does the "if" statement in C evaluate?

A. A condition
B. A loop
C. A function
D. A variable
Answer: A

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

A. auto
B. static
C. dynamic
D. register
Answer: C

24. How do you declare a one-dimensional array in C?

A. int arr[] = {1, 2, 3};
B. array[1, 2, 3];
C. arr(1, 2, 3);
D. int arr = [1, 2, 3];
Answer: A

25. What is the purpose of the "return" statement in a C function?

A. It exits the program.
B. It skips the current loop iteration.
C. It returns a value from the function.
D. It prints a message to the console.
Answer: C

26. Which header file should be included to use the "sqrt" function in C?

A.
B.
C.
D.
Answer: A

27. In C, how do you declare a constant pointer?

A. const ptr;
**B. *const ptr;
*
C. const ptr;
D. ptr const;
Answer: B

28. What is the result of the expression "5 || 0" in C?

A. 0
B. 1
C. 5
D. Error
Answer: B

29. Which function is used to compare two floating-point numbers in C?

A. compare()
B. fp_compare()
C. fequal()
D. fabs()
Answer: D

Top comments (0)