Programming in C MCQ Quiz - Objective Question with Answer for Programming in C - Download Free PDF
Last updated on May 30, 2025
Latest Programming in C MCQ Objective Questions
Programming in C Question 1:
What is the output of the following code?
int i = 1 ;
while ( i <= 10 )
printf ( "%d\n", i );
Answer (Detailed Solution Below)
Programming in C Question 1 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 in C Question 2:
Which of the following is the syntax of the conditional operator in C?
Answer (Detailed Solution Below)
Programming in C Question 2 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 in C Question 3:
Which of the following is a unary operator in C?
Answer (Detailed Solution Below)
Programming in C Question 3 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 in C Question 4:
If a C program contains only one function, it must be __________.
Answer (Detailed Solution Below)
Programming in C Question 4 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.
Programming in C Question 5:
Which operator is used for bitwise OR in C?
Answer (Detailed Solution Below)
Programming in C Question 5 Detailed Solution
In C programming, the bitwise OR operator is: | (single vertical bar)
It performs a bit-by-bit OR operation between two integer operands.
🔍 Example:
int a = 5; / Binary: 0101
int b = 3; / Binary: 0011
int result = a | b; / Result: 0111 = 7
Top Programming in C MCQ Objective Questions
Which programming language is called the mother of programming languages?
Answer (Detailed Solution Below)
Programming in C Question 6 Detailed Solution
Download Solution PDFThe 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:
Answer (Detailed Solution Below)
Programming in C Question 7 Detailed Solution
Download Solution PDFA 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
Answer (Detailed Solution Below)
Programming in C Question 8 Detailed Solution
Download Solution PDFThe 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]);
Answer (Detailed Solution Below)
Programming in C Question 9 Detailed Solution
Download Solution PDFAn 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.
Answer (Detailed Solution Below)
Programming in C Question 10 Detailed Solution
Download Solution PDFThe 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?
Answer (Detailed Solution Below)
Programming in C Question 11 Detailed Solution
Download Solution PDFThe 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.
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 in C Question 12 Detailed Solution
Download Solution PDFinteger 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 |
Who is credited with developing the “C” language?
Answer (Detailed Solution Below)
Programming in C Question 13 Detailed Solution
Download Solution PDFThe 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.
Which one of the following is not an example of computer language?
Answer (Detailed Solution Below)
Programming in C Question 14 Detailed Solution
Download Solution PDFThe 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 |
|
Fortron |
|
Cobol |
|
Considering the size of char (character) variables as one byte, what will be the size of the array declared below?
char array[ ] = “programming language”;Answer (Detailed Solution Below)
Programming in C Question 15 Detailed Solution
Download Solution PDFEach 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.