Programming and Data Structure MCQ Quiz - Objective Question with Answer for Programming and Data Structure - Download Free PDF

Last updated on May 30, 2025

Latest Programming and Data Structure MCQ Objective Questions

Programming and Data Structure Question 1:

Which of the following methods can be used to stop method overriding?

  1. final
  2. static
  3. default
  4. More than one of the above
  5. None of the above

Answer (Detailed Solution Below)

Option 1 : final

Programming and Data Structure Question 1 Detailed Solution

Method Overriding: It is a feature in the programming language that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes. It allows for a specific type of polymorphism (subtyping).

final: It is a non-access modifier that is applicable only for variables, methods and classes. Final variables are used to create constant variables, final methods are used to prevent method overriding and final classes are used to prevent inheritence.

static: It is a non-access modifier that is applicable for blocks, variables, methods and classes. Static methods can only call other static methods directly, they can access only static data directly and they cannot refer to this or super in any way.

default: This modifier is also referred to as no modifier. When no other modifier is in use then it is treated as default where it allows us to access within a class, within a subclass, and also non-sub class within a package. But there is a catch when the package differs, be it a subclass or non-class, we are not able to access it.

Programming and Data Structure Question 2:

What is the output of the following code?
int i = 1 ;
while ( i <= 10 )
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 and Data Structure Question 2 Detailed Solution

The correct option is 4

Concept:

Here’s the given code:

int i = 1;
while (i <= 10)
    printf("%d\n", i);
The condition i <= 10 is true for i = 1.

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 <= 10 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 <= 10 will always be true, causing the printf statement to execute repeatedly without ever reaching a termination condition. It will continuously print "1" followed by a newline character.

Programming and Data Structure Question 3:

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 and Data Structure Question 3 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)

Programming and Data Structure Question 4:

Which of the following is a unary operator in C?

  1. --
  2. +
  3. *
  4. %

Answer (Detailed Solution Below)

Option 1 : --

Programming and Data Structure Question 4 Detailed Solution

Explanation:

Unary Operators in C

A unary operator takes a single operand and applies the operation to it. For example, the increment operator (++) increases the value of its operand by one, while the decrement operator (--) decreases the value of its operand by one. Unary operators are essential in programming for tasks like loop control, value manipulation, and memory management.

Types of Unary Operators in C:

  • Increment Operator (++): Increases the value of its operand by one. It can be used in both prefix (++i) and postfix (i++) forms.
  • Decrement Operator (--): Decreases the value of its operand by one. It can also be used in both prefix (--i) and postfix (i--) forms.
  • Unary Plus (+): Although it doesn’t change the value of its operand, it indicates that the operand is a positive number. It is rarely used in practice.
  • Unary Minus (-): Negates the value of its operand, effectively changing its sign.
  • Logical NOT (!): Inverts the truth value of its operand, turning true into false and vice versa.
  • Bitwise NOT (~): Inverts each bit of its operand, turning 0s into 1s and 1s into 0s.
  • Address-of Operator (&): Returns the memory address of its operand.
  • Indirection Operator (*) or Dereference Operator: Accesses the value stored at the memory address pointed to by a pointer variable.
  • Size of Operator: Returns the size, in bytes, of its operand.
  • Typecast Operator: Converts a variable from one data type to another.

Programming and Data Structure Question 5:

If a C program contains only one function, it must be __________.

  1. primary()
  2. void()
  3. major()
  4. main( )

Answer (Detailed Solution Below)

Option 4 : main( )

Programming and Data Structure Question 5 Detailed Solution

Explanation:

Single Acting Steam Engine

Definition: A single acting steam engine is a type of steam engine where the steam acts on only one side of the piston during its operation, producing one working stroke per revolution of the crankshaft. This configuration contrasts with double-acting steam engines, where the steam alternately acts on both sides of the piston.

Working Principle: In a single acting steam engine, steam is introduced into the cylinder on one side of the piston. The pressure of the steam pushes the piston, converting thermal energy into mechanical work. After the steam has expanded, it is exhausted, and the piston is returned to its original position by a flywheel or another mechanism, ready for the next cycle.

Advantages:

  • Simplicity in design and construction, making it easier to manufacture and maintain.
  • Less mechanical complexity compared to double-acting engines, resulting in fewer parts and potential points of failure.

Disadvantages:

  • Lower efficiency as only one side of the piston is used for performing work.
  • Requires a more substantial flywheel to maintain smooth operation due to the intermittent power delivery.

Applications: Single acting steam engines are commonly used in smaller applications where simplicity and cost are critical factors, such as in some types of pumps and small locomotives.

Correct Option Analysis:

The correct option for a C program containing only one function is:

Option 4: main()

This is because in the C programming language, the main() function is the entry point of any C program. When a C program is executed, the execution starts from the main() function. This function is mandatory for every C program, and without it, the program will not run. The main() function can take arguments (usually for command-line inputs), but it must be present in every C program.

Additional Information

To further understand the analysis, let’s evaluate the other options:

Option 1: primary()

This is not a valid function name in C that signifies the entry point of the program. While 'primary' might be used as a function name, it does not have the special significance or required presence that main() does.

Option 2: void()

This is incorrect. 'void' is a keyword in C that specifies that a function does not return a value. It cannot be used as a function name and certainly cannot replace main().

Option 3: major()

This is also incorrect. 'major' can be used as a function name, but like 'primary', it does not have any special significance in the C programming language. It is not the designated entry point of a C program.

Conclusion:

Understanding the role of the main() function is crucial for programming in C. It is the starting point of execution and is mandatory for every C program. Without the main() function, a C program cannot execute, which is why it is the correct option among the given choices.

Top Programming and Data Structure MCQ Objective Questions

Which of the following is not a computer language?

I. C++

II. Java

III. Linux

  1. Only I
  2. Only III
  3. II and III
  4. I and II

Answer (Detailed Solution Below)

Option 2 : Only III

Programming and Data Structure Question 6 Detailed Solution

Download Solution PDF

C++

Computer Language

Java

Computer Language

Linux

Operating System

 

Additional Information

  • Computer Language - A programming language is a vocabulary and set of grammatical rules for instructing a computer or computing device to perform specific tasks.
  • Operating System - is system software that manages computer hardware and software resources and provides common services for other computer programs.

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 and Data Structure Question 7 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 and Data Structure Question 8 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 and Data Structure Question 9 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 and Data Structure Question 10 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, 

F2 Harshita Madhuri 12.02.2022 D2

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 and Data Structure Question 11 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 and Data Structure Question 12 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 and Data Structure Question 13 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 < 5; 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 and Data Structure Question 14 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 and Data Structure Question 15 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.
Get Free Access Now
Hot Links: teen patti master gold apk teen patti master download teen patti wala game teen patti online game teen patti dhani