Home » C language MCQ Part 2 (Multiple Choice Questions)

C language MCQ Part 2 (Multiple Choice Questions)

by Online Tutorials Library

C language MCQ Part-2

1) Array is a _________ data structure.

  1. Non-linear
  2. Primary
  3. Linear
  4. Data type

Answer: (c) Linear

Explanation: An array is a non-primitive and linear data structure that only stores a similar data type.


2) Which of the following statement is correct about the array?

  1. In the array, users can only allocate the memory at the run time.
  2. In the array, users can only allocate the memory at the compile time.
  3. The array is a primitive and non-linear data structure that only stores a similar data type.
  4. All of the these

Answer: (b) In the array, users can only allocate the memory at the compile time.

Explanation: An array is a non-primitive and linear data structure that only stores a similar data type. In array, users can only allocate the memory at the compile time.


3) Which of the following statement is correct about the C language?

  1. The C language is a binary language with some extra features.
  2. The C language is a high-level language with some low features.
  3. The C language is a mid-level language with some high features.
  4. The C language is a low-level language.

Answer: (c) The C language is a mid-level language with some high features.

Explanation: C is considered a middle-level language because it supports the feature of both low-level and high-level languages. Today, many programmers refer to C as a low-level language because it lacks a large runtime system (no garbage collection, etc.). It supports only scalar operations and provides direct memory addressing.


4) In the following program fragment, s and b are two integers:

What does it intend to do?

  1. Exchange the values of s and b
  2. Transfer the values of s and b
  3. Transfer the values of b and s
  4. Add or subtract the values of s and b

Answer: (a) Exchange the values of s and b

Explanation: The intention of this program fragment is to exchange (swap) the values of s and b. Let us take an example for better understand:


5) Study the following program fragment

What will be the output of this program fragment?

  1. prints 263
  2. prints the ASCII equivalent of 263
  3. rings the bell
  4. prints garbage

Answer: (c) rings the bell

Explanation: 263 is equivalent to binary number 100000111. If the user tries to print an integer as a character, only the last 8 bits are considered, and the remaining ones are ignored. In this program, the ASCII value of 100000111 will be 00000111 (i.e., decimal 7). Therefore, this program will print “ringing the bell”.


6) Study the following statement

What will be the output of this statement?

  1. 1.8
  2. 1.0
  3. 2.0
  4. None of the these

Answer: (d) None of the these

Explanation: On execution, 9/5 will produce integer 1. If we print 1 as a floating number, only garbage will be printed.


7) A global variable is declared __________.

  1. Outside of the function
  2. Inside of the function
  3. With the function
  4. Anywhere in the program

Answer: (a) Outside of the function

Explanation: A global variable is a variable that is declared outside of the function. A global variable can be used in all functions.


8) Who defines the user-defined function?

  1. Compiler
  2. Computer
  3. Compiler library
  4. Users

Answer: (d) Users

Explanation: The user-defined functions are those functions that are defined by the user while writing the program. The user can define these functions according to their needs.


9) Which of the following functions is already declared in the “header file”?

  1. User-define function
  2. Built-in function
  3. C function
  4. None of the these

Answer: (b) Built-in function

Explanation: Built-in functions are those functions whose prototypes are preserved in the header file of the “C” programming language. These functions are called and executed only by typing their name in the program. For example, scanf(), printf(), strcat(), etc.


10) Which of the following operations cannot be performed in file handling?

  1. Open the file
  2. Read the file
  3. To write a file
  4. None of the these

Answer: (d) None of the these

Explanation: File handling is a process in which data is stored in a file using a program. The following operations can be performed in file handling:

  • Create a new file
  • Open file
  • Read the file
  • Write the file
  • Delete file
  • File closing

Therefore, option (d) is the correct answer.


11) Which of the following function is used to write the integer in a file?

  1. getw()
  2. putw()
  3. int value
  4. f_int()

Answer: (b) putw()

Explanation: The putw() is used to write the integer in a file.

Syntax:

putw(int i, FILE *fp);

12) Which of the following statement is correct about the ftell() function?

  1. It returns the current position.
  2. It sets the file pointer to the given position.
  3. It sets the file pointer at the beginning of the file.
  4. It reads a character from the file.

Answer: (a) It returns the current position.

Explanation: The ftell() function returns the current position of the file pointer in a stream.

Syntax of ftell() function:


13) Study the following program:

What will be the output of this program?

  1. 2
  2. 6
  3. 4
  4. 1

Answer: (a) 1

Explanation: The expression can be treated as i = (++i == 6), because “==” is of higher precedence than “=” operator. In the inner expression, ++i is equal to 6. Hence, the result is 1.


14) In which of the following modes, the user can read and write the file?

  1. r
  2. w
  3. r+
  4. b+

Answer: (c) r+

Explanation: r+ mode opens the text file in both reads and writes modes.


15) What type of data type does the atoi() function return?

  1. String
  2. char
  3. Integer
  4. Float

Answer: (c) Integer

Explanation: The atoi() takes the string data type and returns the integer data type. This means it converts the string argument into an integer.


16) Which of the following keywords is used to prevent any kind of change in a variable?

  1. continue
  2. const
  3. struct
  4. extern

Answer: (b) const

Explanation: Constant is a variable whose value cannot be changed once assigned. Constant is also called literals. It can be of any basic data type such as char, integer, float, and string. It can be defined anywhere in the program but in a new line. It is represented by the const keyword.


17) Which of the following declarations is invalid in C language?

  1. char *str = “tutoraspire is the best platform for learn”;
  2. char str[] = “tutoraspire is the best platform for learn”;
  3. char str[20] = “tutoraspire is the best platform for learn”;
  4. char[] str = “tutoraspire is the best platform for learn”;

Answer: (d) char[] str = “tutoraspire is the best platform for learn”;

Explanation: This declaration is valid in java language, but not in C language. Therefore, option (d) is the correct answer.


18) The enum keyword is used to assign names to the ________ constants.

  1. Integer
  2. String
  3. Character
  4. All of the these

Answer: (a) Integer

Explanation: Enumeration is a user-defined data type in C language that is used to assign names to integral constants. It is represented by the “enum” keyword.


19) Study the following program:

What will be the output of this program?

  1. 1
  2. error: redeclaration of an enumerator
  3. h
  4. 3

Answer: (b) error: redeclaration of an enumerator

Explanation: There is a declaration error in the output of this program because the declaration of the enum function is the same.


20) Which of the following operator’s precedence order is correct (from highest to lowest)?

  1. %, *, /, +, –
  2. %, +, /, *, –
  3. +, -, %, *, /
  4. %, +, -, *, /

Answer: (a) %, *, /, +, –

Explanation: The precedence of operator species that which operator will be evaluated first and next. When two operators share an operand, the operator with the higher precedence goes first.


21) Which of the following is not an arithmetic operation?

  1. x * = 65;
  2. x / = 42;
  3. x % = 2;
  4. x ! = 56;

Answer: (d) x ! = 56;

Explanation: There are five arithmetic operators in the C language.

% Modulo division
* Multiplication

You may also like