Javatpoint Logo
Javatpoint Logo

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 = "javatpoint is the best platform for learn";
  2. char str[] = "javatpoint is the best platform for learn";
  3. char str[20] = "javatpoint is the best platform for learn";
  4. char[] str = "javatpoint is the best platform for learn";

Answer: (d) char[] str = "javatpoint 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.


22) Which of the following operator is represented a relational operation?

  1. ==
  2. ++
  3. ||
  4. &&

Answer: (a) ==

Explanation: The relational expression is used to compare two operands. It is a condition expression. The following operators are relational operators.

% Modulo division
* Multiplication
/ Division
+ Addition
- Subtraction
== Equal to
!= Not equal to
< Less than
> Greater than
<= Less than or equal to)
>= Greater than or equal to

23) Which of the following keyword is used for union in c language?

  1. un
  2. unt
  3. ion
  4. union

Answer: (d) union

Explanation: Union is a special data type by which we store different data types in the same memory location. The union keyword is used to define a union data type.


24) Study the following program fragment

What will store in ch?

  1. Z
  2. 90
  3. 91
  4. 122

Answer: (b) 90

Explanation: The capital 'Z' value is 90 accordingly to the ASCII table. Therefore, 90 will be assigned to ch variable.


25) Study the following program:

What will be the output of this program?

  1. ENQ
  2. 5
  3. I
  4. Not equal to 5

Answer: (b) 5

Explanation: This program will print 5 because '5' is a decimal value, and it is equal to 53 in the ASCII table. Therefore, the condition is true and returns 5.


26) Which of the following variable name is correct in c language?

  1. For
  2. for
  3. Basic salary
  4. hello.

Answer: (a) For

Explanation: The "for" is an incorrect variable name because it is a keyword in the C language. The "Basic salary" is the incorrect variable name because space is not allowed within the variable name. Hello. is incorrect because '.' is not allowed within the variable name. Therefore, option (a) is the correct answer.


27) Which of the following header files is not used in C language?

  1. <assert.h>
  2. <ctype.h>
  3. <iostream.h>
  4. <locale.h>

Answer: (c) <iostream.h>

Explanation: <iostream.h> header file is used for basic input and output services in C++ language.


28) Which of the following header files is used for character type function in C language?

  1. <assert.h>
  2. <ctype.h>
  3. <iostream.h>
  4. <locale.h>

Answer: (b) <ctype.h>

Explanation: The <ctype.h> header file is used for character type function in C language.


29) Which of the following declaration is incorrect in C language?

  1. scanf("%d%d", a, b);
  2. scanf("%d%d", a b);
  3. scanf("First %d Second %d", &a, &b);
  4. scanf(" %d%d", &x,&y);

Answer: (b) scanf("%d%d", a b);

Explanation: Option (b) is an incorrect declaration in the C language because the variable name is not separated by a comma.


30) If a = 0x6db7, what will be the value of "a << 6" in decimal?

  1. 28087
  2. 28996
  3. 29512
  4. 29096

Answer: (a) 28087

Explanation: a = 0x6db7, that means, 0x6db7 is a hexadecimal code.

=0x6db7 << 6 = 0110 1101 1011 0111 << 6

= 0110 1101 1100 0000

= 28087 (in decimal)


31) If a = 0x6db7 and b = 0xa726, what will be the value of a&b?

  1. 9814
  2. 9510
  3. 9045
  4. 9305

Answer: (b) 9510

Explanation: a = 0x6db7

b = 0xa726

Both a and b values are hexadecimal value.

= 0x6db7 & 0xa726

= 0110 1101 1011 0111 & 1010 0111 0010 0110

= 0010 0101 0010 0110

= 0x2526

= 9510 (in decimal)


32) If a = 0x6db7 and b = 0xa726, what will be the value of a^b?

  1. 51956
  2. 51256
  3. 51857
  4. 51235

Answer: (c) 51587

Explanation: a = 0x6db7

b = 0xa726

Both a and b values are hexadecimal value.

= 0110 1101 1011 0111 ^ 1010 0111 0010 0110

= 1100 1010 1001 0001

= 0xca91

= 51857 (in decimal)


33) Study the following program:

What will be the output of this program?

  1. 10
  2. 9
  3. 5
  4. 3

Answer: (c) 5

Explanation: x = 4 % -5 + 6 % 5

x = 4 + 6 % 5

x = 4 + 1

x = 5


34) Study the following program:

What will be the output of this program?

  1. A + 5
  2. A
  3. 5
  4. F

Answer: (d) F

Explanation: This program will print F because capital 'A' is equal to 65 according to the ASCII table. Therefore, 'A + 5' is equal to 70, and the value of 70 is F.


35) Which one of the following operators is a unary operator in c language?

  1. &
  2. &&
  3. <<
  4. sizeof()

Answer: (d) sizeof()

Explanation: The sizeof () operator is a compile-time unary operator that is used to compute the size of the operand.


36) Study the following program:

What will be the output of this program?

  1. 510
  2. 105
  3. Compiler error
  4. Declaration error

Answer: (b) 105

Explanation: None


37) How many types of variables are there in the C language?

  1. 2
  2. 4
  3. 1
  4. 5

Answer: (a) 2

Explanation: There are two types of variables:

  • Global variable
  • Local variable

38) Which of the following is the variable that can be used for all functions?

  1. Static variable
  2. Global variable
  3. Local variable
  4. Dynamic variable

Answer: (b) Global variable

Explanation: The global variable is a variable, which is declared outside of the functions. A global variable can be used in all functions.


39) Which symbol is used to declare a pointer?

  1. *
  2. #
  3. &
  4. &&

Answer: (a) *

Explanation: To declare a pointer variable, we use a '*' symbol before the pointer variable.


40) Which of the following initialization is incorrect in C language?

  1. char str [40] = "YUGAL";
  2. char str [] = {'Y','U','G','A','L','\ 0'};
  3. char str [40] = {'Y','U','G','A','L','\ 0'};
  4. None of the these

Answer: (d) None of the these

Explanation: All these declarations are correct in the C language. Therefore, option (d) is the correct answer.


Next Topic#





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA