C PROGRAMMING
MULTIPLE CHOICE QUESTION
OLD QUESTION BANK
SAMPLE QUESTION 2080 AND SOLUTION

Introduction to C programming:

C TOKENS

1. Which of the following is NOT a valid C token?

a) Identifier

b) Keyword

c) Comment

d) Variable

Answer: c) Comment

 

2. Which type of token is used to represent a function or variable name in C?

a) Identifier

b) Keyword

c) Operator

d) Punctuator

Answer: a) Identifier

 

3. Which of the following is a keyword in C?

a) String

b) Float

c) Class

d) Print

Answer: b) Float


4. What type of token is represented by the symbol "+" in C?

a) Identifier

b) Keyword

c) Operator

d) Punctuator

Answer: c) Operator


5. Which of the following is a valid integer constant in C?

a) 3.14

b) 'A'

c) "Hello"

d) 42

Answer: d) 42


6. What type of token is represented by the symbol ";" in C?

a) Identifier

b) Keyword

c) Operator

d) Punctuator

Answer: d) Punctuator


7. Which of the following is a valid string literal in C?

a) 'Hello'

b) "World"

c) 3.14

d) 42

Answer: b) "World"

 

8. Which token is used to assign a value to a variable in C?

a) Identifier

b) Keyword

c) Operator

d) Punctuator

Answer: c) Operator


9. Which of the following is a valid character constant in C?

a) 3.14

b) 'A'

c) "Hello"

d) 42

Answer: b) 'A'


10. What type of token is represented by the symbol "{" in C?

a) Identifier

b) Keyword

c) Operator

d) Punctuator

Answer: d) Punctuator

 

OPERATORS

11. Which operator in C is used for assignment?

a) =

b) ==

c) +=

d) /

Answer: a) =

 

12.  Which operator in C is used for equality comparison?

a) =

b) ==

c) !=

d) >

Answer: b) ==


13. Which operator in C is used for not equal to comparison?

a) =

b) ==

c) !=

d) >

Answer: c) !=

 

14. Which operator in C is used for greater than comparison?

a) =

b) ==

c) !=

d) >

Answer: d) >

 

15. Which operator in C is used for logical AND?

a) &&

b) ||

c) !

d) &

Answer: a) &&

 

16. Which operator in C is used for logical OR?

a) &&

b) ||

c) !

d) &

Answer: b) ||


FORMATTED/UNFORMATTED INPUT /OUTPUT

17. Which function in C is used to read formatted input from the standard input (keyboard)?

a) scanf()

b) gets()

c) read()

d) fgets()

Answer: a) scanf()


18. Which function in C is used to read unformatted input from the standard input (keyboard)?

a) scanf()

b) gets()

c) read()

d) fgets()

Answer: b) gets()

 

19. Which function in C is used to write formatted output to the standard output (console)?

a) printf()

b) puts()

c) write()

d) fputs()

Answer: a) printf()


20. Which function in C is used to write unformatted output to the standard output (console)?

a) printf()

b) puts()

c) write()

d) fputs()

Answer: b) puts()


21. Which function in C is used to read a line of text (including spaces) from a file?

a) scanf()

b) gets()

c) read()

d) fgets()

Answer: d) fgets()


22. Which function in C is used to write a line of text to a file?

a) printf()

b) puts()

c) write()

d) fputs()

Answer: d) fputs()


23. Which function in C is considered unsafe for reading input due to potential buffer overflow?

a) scanf()

b) gets()

c) read()

d) fgets()

Answer: b) gets()


24. Which function in C is used to read formatted input from a file?

a) scanf()

b) gets()

c) read()

d) fscanf()

Answer: d) fscanf()


25. Which function in C is used to write formatted output to a file?

a) printf()

b) puts()

c) write()

d) fprintf()

Answer: d) fprintf()


26. Which function in C is used to read a single character from the standard input?

a) getchar()

b) getc()

c) fgetc()

d) read()

Answer: a) getchar()


CONTROL STATEMENT 


27. Which control statement in C is used to perform a certain set of statements repeatedly as long as a condition is true?

a) if-else statement

b) switch statement

c) for loop

d) do-while loop

Answer: d) do-while loop


28. Which control statement in C is used to select one of many code blocks to be executed based on the value of an expression?

a) if-else statement

b) switch statement

c) for loop

d) while loop

Answer: b) switch statement


29. Which control statement in C is used to perform a certain set of statements repeatedly until a condition becomes false?

a) if-else statement

b) switch statement

c) if statement

d) while loop

Answer: d) while loop


30. Which control statement in C is used to terminate the current iteration of a loop and proceed to the next iteration?

a) break statement

b) continue statement

c) return statement

d) exit statement

Answer: b) continue statement


31. Which control statement in C is used to exit from a loop or switch statement prematurely?

a) break statement

b) continue statement

c) return statement

d) exit statement

Answer: a) break statement


32. Which control statement in C is used to return a value from a function?

a) break statement

b) continue statement

c) return statement

d) exit statement

Answer: c) return statement

 

33. Which control statement in C is used to jump to a specific point in the code?

a) break statement

b) continue statement

c) return statement

d) goto statement

Answer: d) goto statement


34. Which control statement in C is used to execute a set of statements at least once before checking the loop condition?

a) if-else statement

b) switch statement

c) for loop

d) do-while loop


Answer: d) do-while loop

 

LOOPING IN C

 

35. Which loop in C is used when the number of iterations is known beforehand?

a) for loop

b) while loop

c) do-while loop

d) switch loop

Answer: a) for loop


36. Which control statement in C is used when the number of iterations is not known beforehand?

a) for loop

b) while loop

c) if-else

d) switch 

Answer: b) while loop

 

37. Which loop in C is guaranteed to execute the loop body at least once?

a) for loop

b) while loop

c) do-while loop

d) switch loop

Answer: c) do-while loop

 

38. What is the purpose of the loop control variable in a for loop?

a) To determine the loop condition

b) To keep track of the loop iterations

c) To store the loop body statements

d) To control the loop termination

Answer: b) To keep track of the loop iterations


39. What is the structure of a for loop in C?

a) for (initialization; condition; increment/decrement)

b) for (condition; increment/decrement; initialization)

c) for (condition; initialization; increment/decrement)

d) for (increment/decrement; initialization; condition)


Answer: a) for (initialization; condition; increment/decrement)



40. What is the purpose of the loop condition in a while loop?

a) To determine the loop termination

b) To control the loop increment/decrement

c) To initialize the loop control variable

d) To execute the loop body

Answer: a) To determine the loop termination

 

41. What is the structure of a while loop in C?

a) while (condition) { }

b) while { condition }

c) while { }

d) while (condition) :

Answer: a) while (condition) { }



42. What is the purpose of the loop condition in a do-while loop?

a) To determine the loop termination

b) To control the loop increment/decrement

c) To initialize the loop control variable

d) To execute the loop body


Answer: a) To determine the loop termination


43. What is the structure of a do-while loop in C?

a) do { } while (condition);

b) do while (condition) { };

c) do while { condition } ;

d) do { } (condition) ;

Answer: a) do { } while

 

USER DEFINED FUNCTIONS

44. What is the purpose of a user-defined function in C?

a. To perform complex calculations

b. To reuse code and improve modularity

c. To declare variables

d. To handle input/output operations

Answer: b. To reuse code and improve modularity


45. How is a user-defined function declared in C?

a. By using the keyword "function"

b. By specifying the return type, function name, and parameters

c. By using the keyword "define"

d. By declaring it inside the main function


Answer: b. By specifying the return type, function name, and parameters


46. Which keyword is used to define a function in C?

a. define

b. function

c. void

d. Return


Answer: c. void


48. Which type of function does not return any value in C?

a. Void function

b. Int function

c. Char function

d. Float function


Answer: a. Void function


49. What is the purpose of a function prototype in C?

a. To define the function body

b. To declare the function before it is used

c. To specify the return type of the function

d. To pass arguments to the function


Answer: b. To declare the function before it is used


50. How are function arguments passed in C?

a. By value

b. By reference

c. By pointer

d. By name

Answer: a. By value


51. What is the keyword used to exit a function and return a value in C?

a. break

b. return

c. exit

d. Quit


Answer: b. Return

52. Can a function call itself in C?

a. Yes, it is called a recursive function

b. No, it is not allowed

c. Only if the function is declared as void

d. Only if the function is declared as static

Answer: a. Yes, it is called a recursive function


53. What is the maximum number of parameters a function can have in C?

a. 10

b. 32

c. 64

d. There is no maximum limit


Answer: d. There is no maximum limit

 

54. Which statement is used to call a user-defined function in C?

a. execute function

b. call function

c. invoke function

d. Function


Answer: b. call function

 

RECURSIVE FUNCTION

 

55. What is a recursive function in C?

a. A function that calls itself

b. A function that uses loops instead of recursion

c. A function that accepts multiple arguments

d. A function that returns multiple values


Answer: a. A function that calls itself


56. What is the base case in a recursive function?

a. The condition that determines when the function should terminate

b. The initial value of the function's variables

c. The maximum number of recursive calls allowed

d. The statement that calls the function recursively


Answer: a. The condition that determines when the function should terminate



57. Which of the following is an advantage of using recursive functions?

a. Recursive functions are always more efficient than iterative functions

b. Recursive functions make code easier to understand and maintain

c. Recursive functions consume less memory compared to iterative functions

d. Recursive functions can solve any problem, regardless of complexity

Answer: b. Recursive functions make code easier to understand and maintain


58. What happens if a recursive function does not have a base case?

a. The function will terminate with an error

b. The function will run indefinitely and may cause a stack overflow

c. The function will return the value of the last recursive call

d. The function will automatically generate a default base case


Answer: b. The function will run indefinitely and may cause a stack overflow

59. When should you use a recursive function instead of an iterative solution?

a. When the problem can be divided into smaller subproblems

b. When efficiency is the top priority

c. When the problem requires a large number of repetitive operations

d. When the problem involves complex mathematical calculations

Answer: a. When the problem can be divided into smaller subproblems


60. Which data structure is typically used to implement recursion in C?

a. Arrays

b. Linked lists

c. Stacks

d. Queues

Answer: c. Stacks


61. What is the disadvantage of using recursive functions?

a. Recursive functions are harder to debug than iterative functions

b. Recursive functions can only solve simple problems

c. Recursive functions are slower compared to iterative functions

d. Recursive functions can lead to infinite loops if not implemented correctly


Answer: a. Recursive functions are harder to debug than iterative functions


62. What is the maximum depth of recursion in C?

a. It depends on the specific compiler and system

b. 100 levels

c. 1000 levels

d. There is no maximum depth of recursion in C

Answer: a. It depends on the specific compiler and system

ARRAY(1-D,2-D,MULTIDIMENSIONAL)

63. What is an array in C?

a. A variable that can hold multiple values of the same data type

b. A function that performs mathematical operations on numbers

c. A loop that iterates over a sequence of elements

d. A data structure used to store complex data types


Answer: a. A variable that can hold multiple values of the same data type


64. How do you declare a 1-dimensional array in C?

a. int array[size]

b. array[size]

c. int[size] array

d. size int array[]


Answer: a. int array[size]


65. What is the index range of a 1-dimensional array with N elements?

a. 0 to N-1

b. 1 to N

c. -N to N

d. -N+1 to N

Answer: a. 0 to N-1


66. How do you access an element in a 1-dimensional array in C?

a. array(index)

b. array[index]

c. array{index}

d. array.index

Answer: b. array[index]


67. How do you declare a 2-dimensional array in C?

a. int array[rows][columns]

b. array[rows][columns]

c. int[rows][columns] array

d. rows int[columns] array


Answer: a. int array[rows][columns]

 

68. What is the index range of a 2-dimensional array with R rows and C columns?

a. 0 to R-1, 0 to C-1

b. 1 to R, 1 to C

c. -R to R, -C to C

d. -R+1 to R, -C+1 to C

Answer: a. 0 to R-1, 0 to C-1


70. How do you access an element in a 2-dimensional array in C?

a. array(row, column)

b. array[row][column]

c. array{row, column}

d. array.row.column

Answer: b. array[row][column]

 

71. What is the maximum number of dimensions allowed for an array in C?

a. 1

b. 2

c. 3

d. There is no specific limit

Answer: d. There is no specific limit

 

72. How do you declare a multidimensional array in C?

a. int array[dim1][dim2]...[dimN]

b. array[dim1][dim2]...[dimN]

c. int[dim1][dim2]...[dimN] array

d. dim1 int[dim2]...[dimN] array

Answer: a. int array[dim1][dim2]...[dimN]


73. How do you access an element in a multidimensional array in C?

a. array(index1, index2, ..., indexN)

b. array[index1][index2]...[indexN]

c. array{index1, index2, ..., indexN}

d. array.index1.index2...indexN

Answer: b. array[index1][index2]...[indexN]


STRING MANIPULATION 

74. Which library should be included to perform string manipulation in C?

a. stdlib.h

b. math.h

c. string.h

d. Stdio.h

Answer: c. string.h


75. Which function is used to calculate the length of a string in C?

a. strlen()

b. strcpy()

c. strcat()

d. strcmp()

Answer: a. strlen()

76. Which function is used to copy one string to another in C?

a. strlen()

b. strcpy()

c. strcat()

d. strcmp()

Answer: b. strcpy()

77. Which function is used to concatenate two strings in C?

a. strlen()

b. strcpy()

c. strcat()

d. strcmp()


Answer: c. strcat()

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

a. strlen()

b. strcpy()

c. strcat()

d. strcmp()


Answer: d. strcmp()

 

79. How do you declare a string in C?

a. char str[];

b. char[] str;

c. string str;

d. char* str;

Answer: a. char str[];

 

80. How do you input a string from the user in C?

a. scanf("%s", str);

b. gets(str);

c. fgets(str, sizeof(str), stdin);

d. All of the above



 

Answer: d. All of the above



 

What is the character used to mark the end of a string in C?

a. Period (.)

b. Exclamation mark (!)

c. Null character (\0)

d. Dollar sign ($)

Answer: c. Null character (\0)