Programming in C MCQ Quiz - Objective Question with Answer for Programming in C - Download Free PDF

Last updated on Jun 10, 2025

C programming language is a high-level structured oriented programming language, used for general-purpose programming requirements. It was developed at Bell Laboratories in the early 1970s by Dennis Ritchie. MCQs related to C programming can cover topics such as syntax, keywords, data types, functions, loops, arrays, and pointers, providing an effective way to test a programmer's understanding and proficiency in this language. These topics are important for candidates preparing for govt. exams with Computers as one of the syllabus components. Check how much you know about this programming language by practicing Programming in C MCQs given here.

Latest Programming in C MCQ Objective Questions

Programming in C Question 1:

int z, x = 5, y = -10, a = 4, b = 2;

z = x++ - --y * b / a;

Then z = ?

  1. 5
  2. 6
  3. 10
  4. 11
  5. None of the above

Answer (Detailed Solution Below)

Option 3 : 10

Programming in C Question 1 Detailed Solution

The correct answer is 10

SOLUTION:

Let's break down the expression step by step:

  • x++: Post-increment x, so the current value of x (5) is used in the expression, and then x is incremented to 6.
  • --y: Pre-decrement y, so y is decremented to -11, and the new value (-11) is used in the expression.
  • --y * b: Multiply the decremented value of y (-11) by b (2), which results in -22.
  • -22 / a: Divide -22 by a (4), resulting in -5.5.
  • z = 5 - (-5.5): Subtract -5.5 from 5, which gives 10.5.

However, since z is an integer, the fractional part is truncated, and z is assigned the value 10.

Programming in C Question 2:

Which of the following is a logical bitwise operator ?

  1. *
  2. /
  3. &
  4. +
  5. None of the above

Answer (Detailed Solution Below)

Option 3 : &

Programming in C Question 2 Detailed Solution

The correct answer is &.

Key Points

  • & is a bitwise AND operator in many programming languages, including C, C++, Java, and Python.
  • The bitwise AND operator performs a binary AND operation on two bits or binary numbers, returning a result where each bit is set to 1 if both corresponding bits of the operands are 1, and to 0 otherwise.
  • It is used to manipulate individual bits of data, useful in low-level programming, such as system programming or embedded systems.
  • Common applications include bit masking, where specific bits of a number are isolated or altered, and setting, clearing, or toggling individual bits.

Additional Information

  • Bitwise Operators in General
    • Bitwise operators are used to perform operations on individual bits of data.
    • Common bitwise operators include AND (&), OR (|), XOR (^), NOT (~), left shift (>).
    • These operators are essential in various applications, such as cryptography, network programming, and error detection algorithms.
  • Bit Masking
    • Bit masking is a technique used to extract or manipulate specific bits within a binary number.
    • A mask is created by setting specific bits to 1 and performing a bitwise AND operation with the target number.
    • This technique is commonly used in embedded systems and hardware programming to control individual bits of registers.
  • Bitwise Shift Operations
    • Bitwise shift operations, such as left shift (>), move bits to the left or right within a binary number.
    • Left shifting a binary number by one position is equivalent to multiplying it by 2, while right shifting is equivalent to dividing it by 2.
    • These operations are efficient and commonly used in algorithms requiring fast multiplication or division by powers of 2.
  • Logical vs. Bitwise Operators
    • Logical operators (&&, ||, !) operate on boolean values and return boolean results.
    • Bitwise operators operate on integer values at the binary level and return integer results.
    • Understanding the distinction between these operators is crucial for writing efficient and correct code, especially in system-level programming.

Programming in C Question 3:

The ternary operator can be used as a replacement for which loop/statement?

  1. If-else statement
  2. For loop
  3. While loop
  4. Switch-case statement
  5. None of the above

Answer (Detailed Solution Below)

Option 1 : If-else statement

Programming in C Question 3 Detailed Solution

The correct answer is: 1) If-else statement

Explanation:
The ternary operator (condition ? expr1: expr2) is a shorthand for a simple if-else statement. It evaluates a condition and returns one of two expressions based on whether the condition is true or false.

Option Analysis

  • For loop → The ternary operator cannot replace iterative loops (it lacks repetition logic).
  • While loop → Same as above; loops require repeated execution, which the ternary operator cannot do.
  • Switch-case statement → The ternary operator handles binary (true/false) conditions, not multi-way branching.

Example:
C Programming
/ Using if-else:
if (x > 10) {
    y = 100;
} else {
    y = 0;
}

/ Equivalent ternary:
y = (x > 10) ? 100 : 0;

Programming in C Question 4:

What is the output of the following code?
int i = 1 ;
while ( i printf ( "%d\n", i );

  1. 10 9 8 7 6 5 4 3 2 1
  2. 1 2 3 4 5 6 7 8 9 10
  3. 0 1 2 3 4 5 6 7 8 9
  4. Infinite loop

Answer (Detailed Solution Below)

Option 4 : Infinite loop

Programming in C Question 4 Detailed Solution

The correct option is 4

Concept:

Here’s the given code:

int i = 1;
while (i     printf("%d\n", i);
The condition i

The printf() statement runs and prints 1.

But there is no increment (i++) inside the loop.

The variable i is initialized to 1. The while loop continues if the condition i is true.

However, no statement within the loop increments the value of i.

Therefore, the value of i will always remain 1, and the condition i

Programming in C Question 5:

Which of the following is the syntax of the conditional operator in C?

  1. expression1 ? expression2 : expression3
  2. expression || expression1 && expression2
  3. condition1 : expression1 ? expression2
  4. condition1 && expression1 || expression2

Answer (Detailed Solution Below)

Option 3 : condition1 : expression1 ? expression2

Programming in C Question 5 Detailed Solution

The correct answer is: 1) expression1? expression2 : expression3

Explanation:

The conditional operator (also called the ternary operator) in C has the following syntax:

Condition? expression_if_true : expression_if_false
How It Works:
The condition is evaluated first.

  • If true, expression_if_true is executed.
  • If false, expression_if_false is executed.


Example:
C programming:
int x = 10, y = 20;
int max = (x > y) ? x : y;  / Returns 20 (since y is larger)

Top Programming in C MCQ Objective Questions

Which programming language is called the mother of programming languages?

  1. C++
  2. C
  3. Java
  4. COBOL

Answer (Detailed Solution Below)

Option 2 : C

Programming in C Question 6 Detailed Solution

Download Solution PDF

The Correct Answer is Option (2) i.e C.

  • The C language is also known as the mother of all programming languages.
  • C is a general-purpose programming language that is used for creating a variety of applications.
  • C language was originally developed for writing operating systems. Unix Kernel and all of its supporting tools and libraries are written in C language.
  • The C language is used for the following operations :
    • Operating systems
    • Development of new languages
    • Computation platforms
    • Embedded systems
    • Graphics and Games
  • C++ and Java are the high-level languages and COBOL is a compiled English-like computer programming language.

Valid character constants are:

  1. '\n'
  2. '\\'
  3. Both of the above
  4. None of the above

Answer (Detailed Solution Below)

Option 3 : Both of the above

Programming in C Question 7 Detailed Solution

Download Solution PDF

A character constant is one or more characters enclosed in single quotes, such as 'A' , '+' , or '\n'. 

Backslash_character Meaning
\b Backspace
\f Form feed
\n New line
\r Carriage return
\t Horizontal tab
\” Double quote
\’ Single quote
\\ Backslash
\v Vertical tab
\a Alert or bell
\? Question mark
\N Octal constant (N is an octal constant)
\XN Hexadecimal constant (N – hex.dcml cnst)
 

Consider the following C declaration

struct {

short s[5];

union {

float y;

long z;

}u;

}t;

Assume that objects of type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, is

  1. 22 bytes
  2. 18 bytes
  3. 14 bytes
  4. 10 bytes

Answer (Detailed Solution Below)

Option 2 : 18 bytes

Programming in C Question 8 Detailed Solution

Download Solution PDF

The correct answer is "option 2"

CONCEPT:

Structure in C is a user-defined data type that is used to store the collection of different data types.

The total size of the structure is the sum of the size of every data member.

Union is a user-defined data type that is used to store different data types in the same memory location.

The total size of the union is the size of the largest data member.
 

EXPLANATION:

Given the size of short, float and long is 2 bytes, 4 bytes, and 8 bytes, respectively.

Therefore,

Size of Structure → size of ( short s[5] ) + size of Union  

Here, Size of Union = 8 bytes   { largest data member is long }.

Size of short s[5]  2×5  10 bytes

Size of Structure → 10+8 →18 bytes.

Hence, the correct answer is "option 2".

Consider the following array declaration in ‘C’ language:

int array[] = {2, 3, 4, 5};

What will be the output of the following statement?

printf("%d", 2[array]);

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

Answer (Detailed Solution Below)

Option 1 : 4

Programming in C Question 9 Detailed Solution

Download Solution PDF
Key Points

 An array is defined as the collection of similar types of data items stored at contiguous memory locations. Arrays are the derived data type in C programming language which can store the primitive type of data such as int, char, double, float, etc. C array is beneficial if you have to store similar elements.

int array[] = {2, 3, 4, 5}; This array storage be like, 

The above array at index I can be accessed by, a[i], i[a], *(a+i) or *(i+a) all the above representations all are equal and gives the i th index value.

printf(%d', 2[array]); So, it gives the 2nd  index value. i.e 4.

Hence the correct answer is 4.

Additional InformationProgram: 

#include int main() {     int arr[] = { 2, 3, 4, 5 };     printf("%d ",arr[2]);     printf("%d ",2[arr]);     printf("%d ",*(2+arr));     printf("%d ",*(arr+2));     return 0; }

Output: 4 4 4 4

So above given 2nd index value is 4 for all above print statements.

Which of the following viruses codifies itself in an automatic manner, each time it infects and copies the system.

  1. Polymorphic virus
  2. File Allocation Table (FAT) Virus
  3. Overwrite viruses
  4. Multipartite virus

Answer (Detailed Solution Below)

Option 1 : Polymorphic virus

Programming in C Question 10 Detailed Solution

Download Solution PDF

The correct answer is ​Polymorphic virus.

Key Points

  • A polymorphic virus is a complicated computer virus that affects data types and functions.
  • Polymorphic viruses are complex file infectors that can create modified versions of themselves to avoid detection yet retain the same basic routines after every infection.
  • Upon infection, the polymorphic virus duplicates itself by creating usable, albeit slightly modified, copies of itself.
  • To vary their physical file makeup during each infection, polymorphic viruses encrypt their codes and use different encryption keys every time.
  • It is a self-encrypted virus designed to avoid detection by a scanner.

Which of the following is a math library function?

  1. Math.h
  2. int.h 
  3. Stdio.h 
  4. String.h 

Answer (Detailed Solution Below)

Option 1 : Math.h

Programming in C Question 11 Detailed Solution

Download Solution PDF

The correct answer is Math.h

Key Points

  • Math.h: This is a math library in C that provides mathematical functions like sqrt(), pow(), sin(), cos(), etc.

Additional Information

  • int.h: This is not a standard library in C.
  • Stdio.h: This is the standard input/output library in C, used for functions like printf() and scanf().
  • String.h: This is a string handling library in C, used for functions like strlen(), strcmp(), etc.

Who is credited with developing the “C” language?

  1. Bill Gates
  2. Steve Rogers
  3. Dennis Ritchie
  4. Yashwant Kanetkar

Answer (Detailed Solution Below)

Option 3 : Dennis Ritchie

Programming in C Question 12 Detailed Solution

Download Solution PDF

The correct answer is Dennis Ritchie.

Key Points

  • C programming is a general-purpose, procedural, imperative computer programming language created by Dennis M. Ritchie at Bell Telephone Laboratories in 1972 to help build the UNIX operating system.
  • The most extensively used computer language is C. Dennis Ritchie created C, a successor to the programming language B, at Bell Labs between 1972 and 1973 to build tools that ran on Unix.
  • It was used to re-implement the Unix operating system's kernel.
  • Dennis MacAlistair Ritchie was a computer scientist from the United States.
  • He designed the C programming language, as well as the Unix operating system and the B programming language, alongside long-time collaborator Ken Thompson. 

Additional Information

  • William Henry Gates III (Bill Gates) is a business entrepreneur, software developer, investor, author, and philanthropist from the United States. He and his late boyhood buddy Paul Allen co-founded Microsoft.
  • Yashavant Kanetkar is a computer science author from India well known for his publications on programming languages. He has written multiple books on programming in C, C++, VC++, C#,.NET, DirectX, and COM.

Consider the following C program:

#include

int main ( )

{

int a[ ] = {2, 4, 6, 8, 10};

int i, sum = 0, *b = a + 4;

for (i = 0; i

sum = sum + (*b - i) - *(b - i);

printf (“ % d \ n”, sum);

return 0;

}

The output of the above C program is ________.

Answer (Detailed Solution Below) 10

Programming in C Question 13 Detailed Solution

Download Solution PDF

integer pointer b points to 5th element of an static array a

*b = 10 / dereferencing

sum = 0 / initially

Values in loop

 sum = sum + (*b - i) - *(b - i);

i = 0

 sum = 0 + (10 - 0) - *(address_of_5th integer - 0)

 = 10 - *(address_of_5th integer)

 = 10 - 10 = 0

i = 1

 sum = 0 + (10 - 1) - *(address_of_5th integer - 1)

 = 0 + (10 - 1) - *(address_of_4th integer)

 = 9 - 8 = 1

i = 2

 sum = 1 + (10 - 2) - *(address_of_5th integer - 2)

 = 1 + (10 - 2) - *(address_of_3rd integer)

 = 9 - 6 = 3

i = 3

 sum = 3 + (10 - 3) - *(address_of_5th integer - 3)

 = 3 + (10 - 3) - *(address_of_2nd integer)

 = 10 - 4 = 6

i = 4

 sum = 6 + (10 - 4) - *(address_of_5th integer - 4)

 = 6 + (10 - 4) - *(address_of_1st integer)

 = 12 - 2 = 10

Which one of the following is not an example of computer language?

  1. ALGORITHM
  2. FORTRAN
  3. PASCAL
  4. COBOL

Answer (Detailed Solution Below)

Option 1 : ALGORITHM

Programming in C Question 14 Detailed Solution

Download Solution PDF

The correct answer is ALGORITHM.

Key Points

  • An algorithm is a specific procedure for solving a well-defined computational problem.
  • The development and analysis of algorithms are fundamental to all aspects of Computer Science like AI, databases, graphics, networking, OS, etc.
  • Algorithm development is more than just programming.
    • It requires an understanding of the alternatives available for solving a computational problem.
    • It includes the hardware, networking, programming language, and performance constraints that accompany any particular solution.

Additional Information

  • An official language comprising a collection of instructions that produce different kinds of output is a programming language.
  • In computer science, programming languages are used to implement algorithms.
  • Most of the languages of programming consist of computer instructions.
Pascal
  • Pascal language is mostly a teaching language and few industries use this language to write the programs.
  • This language tends to use keywords instead of symbols and braces in the C language.
  • So this language is very easy for beginners to understand than a programming language like C, C++. 
Fortron
  • It is a computer programming language.
  • It was created in 1957 by John Backus.
  • The name produced from the two words FORmula TRANslation.
  • It is commonly used for numeric and scientific computing.
Cobol
  • COBOL stands for Common Business Oriented Language.
  • It is first developed in 1960 by the CODASYL Committee (Conference on Data Systems Languages).
  • It is primarily designed for use in business-oriented applications.

Considering the size of char (character) variables as one byte, what will be the size of the array declared below?

char array[ ] = “programming language”;

  1. 11 Bytes
  2. 8 Bytes
  3. 20 Bytes
  4. 21 Bytes

Answer (Detailed Solution Below)

Option 4 : 21 Bytes

Programming in C Question 15 Detailed Solution

Download Solution PDF

Each character is of one byte:

Byte number and corresponding bytes are given for character array

1st

2nd

3rd

4th

5th

6th

7th

8th

9th

10th

11th

12th

13th

p

r

o

g

r

a

m

m

i

n

g

 

l

 

14th

15th

16th

17th

18th

19th

20th

21st

a

n

g

u

a

g

e

\0

 

Therefore, the size of the array declared is 21 bytes

Important Point:

\0 is null character.

Hot Links: teen patti online teen patti bliss teen patti master apk download teen patti casino download teen patti 500 bonus