C Language MCQ Part 2 (Multiple Choice Questions) - Javatpoint

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

Home C C++ C# Java SQL HTML CSS JavaScript XML Ajax Android

https://www.javatpoint.com/c-language-mcq-part-2 1/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

ADVERTISEMENT

C language MCQ Part-2


1) Array is a _________ data structure.

a. Non-linear

b. Primary

c. Linear

d. Data type

Hide Answer Workspace

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?

a. In the array, users can only allocate the memory at the run time.

b. In the array, users can only allocate the memory at the compile time.

c. The array is a primitive and non-linear data structure that only stores a similar data type.

d. All of the these

Hide Answer Workspace

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?

a. The C language is a binary language with some extra features.

https://www.javatpoint.com/c-language-mcq-part-2 2/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

b. The C language is a high-level language with some low features.

c. The C language is a mid-level language with some high features.

d. The C language is a low-level language.

Hide Answer Workspace

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:

b=s+b
s=b-s
b=b-s

What does it intend to do?

a. Exchange the values of s and b

b. Transfer the values of s and b


https://www.javatpoint.com/c-language-mcq-part-2 3/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

c. Transfer the values of b and s

d. Add or subtract the values of s and b

Hide Answer Workspace

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:

s=1
b=2
b=s+b
b=1+2
b=3
s=b-s
s=3-1
s=2
b=b-s
b=3-2
b=1

5) Study the following program fragment

int i = 263;
putchar(i);

What will be the output of this program fragment?

a. prints 263

b. prints the ASCII equivalent of 263

c. rings the bell

d. prints garbage

Hide Answer Workspace

https://www.javatpoint.com/c-language-mcq-part-2 4/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

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

printf ("%d", 9/5);

What will be the output of this statement?

a. 1.8

b. 1.0

c. 2.0

d. None of the these

Hide Answer Workspace

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 __________.

https://www.javatpoint.com/c-language-mcq-part-2 5/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

a. Outside of the function

b. Inside of the function

c. With the function

d. Anywhere in the program

Hide Answer Workspace

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?

a. Compiler

b. Computer

c. Compiler library

d. Users

Hide Answer Workspace

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"?

a. User-define function

b. Built-in function

c. C function

d. None of the these

Hide Answer Workspace

Answer: (b) Built-in function

https://www.javatpoint.com/c-language-mcq-part-2 6/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

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?

a. Open the file

b. Read the file

c. To write a file

d. None of the these

Hide Answer Workspace

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?

a. getw()

b. putw()

c. int value

d. f_int()

Hide Answer Workspace

Answer: (b) putw()


https://www.javatpoint.com/c-language-mcq-part-2 7/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

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?

a. It returns the current position.

b. It sets the file pointer to the given position.

c. It sets the file pointer at the beginning of the file.

d. It reads a character from the file.

Hide Answer Workspace

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:

long int ftell(FILE *stream)

13) Study the following program:

#include <stdio.h>
int main() {
int i = 5;
printf("%d", i = ++i == 6);
return 0;
}

What will be the output of this program?

https://www.javatpoint.com/c-language-mcq-part-2 8/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

a. 2

b. 6

c. 4

d. 1

Hide Answer Workspace

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?

a. r

b. w

c. r+

d. b+

Hide Answer Workspace

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?

a. String

b. char

c. Integer

https://www.javatpoint.com/c-language-mcq-part-2 9/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

d. Float

Hide Answer Workspace

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?

a. continue

b. const

c. struct

d. extern

Hide Answer Workspace

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?

a. char *str = "javatpoint is the best platform for learn";

b. char str[] = "javatpoint is the best platform for learn";


https://www.javatpoint.com/c-language-mcq-part-2 10/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

c. char str[20] = "javatpoint is the best platform for learn";

d. char[] str = "javatpoint is the best platform for learn";

Hide Answer Workspace

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.

a. Integer

b. String

c. Character

d. All of the these

Hide Answer Workspace

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.

ADVERTISEMENT ADVERTISEMENT

19) Study the following program:

#include<stdio.h>
enum flg{a, b, c};

https://www.javatpoint.com/c-language-mcq-part-2 11/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

enum glf{c, e, f};


main()
{
enum flg h;
h = b;
printf("%d", h);
return 0;
}

What will be the output of this program?

a. 1

b. error: redeclaration of an enumerator

c. h

d. 3

Hide Answer Workspace

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)?

a. %, *, /, +, -

b. %, +, /, *, -

c. +, -, %, *, /

d. %, +, -, *, /

Hide Answer Workspace

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.

https://www.javatpoint.com/c-language-mcq-part-2 12/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

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

a. x * = 65;

b. x / = 42;

c. x % = 2;

d. x ! = 56;

Hide Answer Workspace

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?

a. ==

b. ++

c. ||

d. &&

Show Answer Workspace

% 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

https://www.javatpoint.com/c-language-mcq-part-2 13/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

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

a. un

b. unt

c. ion

d. union

Hide Answer Workspace

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

char ch = 'Z'

What will store in ch?

a. Z

b. 90

c. 91

d. 122

Hide Answer Workspace

Answer: (b) 90

https://www.javatpoint.com/c-language-mcq-part-2 14/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

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:

main ()
{
if(5 < '5')
printf("5")
else
printf("Not equal to 5.")
}

What will be the output of this program?

a. ENQ

b. 5

c. I

d. Not equal to 5

Hide Answer Workspace

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?

a. For

b. for

c. Basic salary

d. hello.

Hide Answer Workspace

https://www.javatpoint.com/c-language-mcq-part-2 15/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

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?

a. <assert.h>

b. <ctype.h>

c. <iostream.h>

d. <locale.h>

Hide Answer Workspace

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?

a. <assert.h>

b. <ctype.h>

c. <iostream.h>

d. <locale.h>

Hide Answer Workspace

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?

https://www.javatpoint.com/c-language-mcq-part-2 16/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

a. scanf("%d%d", a, b);

b. scanf("%d%d", a b);

c. scanf("First %d Second %d", &a, &b);

d. scanf(" %d%d", &x,&y);

Hide Answer Workspace

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?

a. 28087

b. 28996

c. 29512

d. 29096

Hide Answer Workspace

Answer: (a) 28087

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

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

= 0110 1101 1100 0000

https://www.javatpoint.com/c-language-mcq-part-2 17/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

= 28087 (in decimal)

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

a. 9814

b. 9510

c. 9045

d. 9305

Hide Answer Workspace

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?

a. 51956

b. 51256

c. 51857

d. 51235

Hide Answer Workspace

Answer: (c) 51587

Explanation: a = 0x6db7

https://www.javatpoint.com/c-language-mcq-part-2 18/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

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:

main ()
{
int x;
x = 4 % -5 + 6 % 5;
printf("\nx = %d", x);
}

What will be the output of this program?

a. 10

b. 9

c. 5

d. 3

Hide Answer Workspace

Answer: (c) 5

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

x=4+6%5

x=4+1

x=5

https://www.javatpoint.com/c-language-mcq-part-2 19/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

34) Study the following program:

ADVERTISEMENT ADVERTISEMENT

main ()
{
char x;
x = 'A' + 5;
printf("%c", x);
}

What will be the output of this program?

a. A + 5

b. A

c. 5

d. F

Hide Answer Workspace

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?

a. &

b. &&

https://www.javatpoint.com/c-language-mcq-part-2 20/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

c. <<

d. sizeof()

Hide Answer Workspace

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:

#include <stdio.h>
#define a( i, j ) printf("%d", j##i )
int main()
{
a(5, 10);
}

What will be the output of this program?

a. 510

b. 105

c. Compiler error

d. Declaration error

Hide Answer Workspace

Answer: (b) 105

Explanation: None

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

a. 2

b. 4

c. 1
https://www.javatpoint.com/c-language-mcq-part-2 21/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

d. 5

Hide Answer Workspace

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?

a. Static variable

b. Global variable

c. Local variable

d. Dynamic variable

Hide Answer Workspace

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?

a. *

b. #

c. &

d. &&

Hide Answer Workspace

Answer: (a) *

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

https://www.javatpoint.com/c-language-mcq-part-2 22/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

int *k;

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

a. char str [40] = "YUGAL";

b. char str [] = {'Y','U','G','A','L','\ 0'};

c. char str [40] = {'Y','U','G','A','L','\ 0'};

d. None of the these

Hide Answer Workspace

Answer: (d) None of the these

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

← Prev Next →

For Videos Join Our Youtube Channel: Join Now

https://www.javatpoint.com/c-language-mcq-part-2 23/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

Feedback

Send your Feedback to [email protected]

Help Others, Please Share

Learn Latest Tutorials

Splunk SPSS Swagger Transact-SQL

React tutorial Regex tutorial Reinforcement


learning tutorial
ReactJS Regex
Reinforcement
Tumblr Learning

R Programming RxJS tutorial React Native Python Design


tutorial tutorial Patterns
RxJS
R Programming React Native Python Design
Patterns

Python Pillow Python Turtle Keras tutorial


tutorial tutorial
Keras
Python Pillow Python Turtle

Preparation

Aptitude Logical Verbal Ability Interview


Reasoning Questions
Aptitude Verbal Ability
Reasoning Interview Questions

https://www.javatpoint.com/c-language-mcq-part-2 24/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

Company
Interview
Questions
Company Questions

Trending Technologies

Artificial AWS Tutorial Selenium Cloud


Intelligence tutorial Computing
AWS
Artificial Selenium Cloud Computing
Intelligence

Hadoop tutorial ReactJS Data Science Angular 7


Tutorial Tutorial Tutorial
Hadoop
ReactJS Data Science Angular 7

Blockchain Git Tutorial Machine DevOps


Tutorial Learning Tutorial Tutorial
Git
Blockchain Machine Learning DevOps

B.Tech / MCA

DBMS tutorial Data Structures DAA tutorial Operating


tutorial System
DBMS DAA
Data Structures Operating System

Computer Compiler Computer Discrete


Network tutorial Design tutorial Organization and Mathematics
Architecture Tutorial
Computer Network Compiler Design
Computer Discrete
Organization Mathematics

Ethical Hacking Computer Software html tutorial


Graphics Tutorial Engineering
Ethical Hacking Web Technology
Computer Graphics

https://www.javatpoint.com/c-language-mcq-part-2 25/26
2/12/24, 9:18 PM C language MCQ Part 2 (Multiple Choice Questions) - javatpoint

Software
Engineering

Cyber Security Automata C Language C++ tutorial


tutorial Tutorial tutorial
C++
Cyber Security Automata C Programming

Java tutorial .Net Python tutorial List of


Framework Programs
Java Python
tutorial
Programs
.Net

Control Data Mining Data


Systems tutorial Tutorial Warehouse
Tutorial
Control System Data Mining
Data Warehouse

https://www.javatpoint.com/c-language-mcq-part-2 26/26

You might also like