Home Subjects Computer Knowledge C Programming

Computer Knowledge
C Programming

Programming, networking, database and OS questions

60 Q 2 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 11–20 of 60
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.11 Easy C Programming
Which preprocessor directive is used to include a custom header file?
A #include
B #include "filename"
C #include [filename]
D #include {filename}
Correct Answer:  B. #include "filename"
EXPLANATION

Custom/local header files are included using double quotes: #include "filename". Standard library headers use angle brackets: #include <filename>. The compiler searches for quoted files in the current directory first.

Test
Q.12 Easy C Programming
What will be the value of x after executing: int x = 5; x += 3; x *= 2;
A 10
B 16
C 11
D 13
Correct Answer:  B. 16
EXPLANATION
Step 1: x = 5. Step 2: x += 3 means x = x + 3 = 5 + 3 = 8. Step 3: x *= 2 means x = x * 2 = 8 * 2 = 16. Therefore, x = 16.
Test
Q.13 Easy C Programming
What is the scope of a variable declared inside a block?
A Global scope
B Local scope (block scope)
C Static scope
D External scope
Correct Answer:  B. Local scope (block scope)
EXPLANATION

Variables declared inside a block (enclosed in curly braces) have local or block scope. They are accessible only within that block and cease to exist once the block execution is complete.

Test
Q.14 Easy C Programming
Which loop construct in C guarantees execution at least once?
A while loop
B for loop
C do-while loop
D nested loop
Correct Answer:  C. do-while loop
EXPLANATION

The do-while loop executes the body at least once before checking the condition. The syntax is: do { statements; } while(condition);. In contrast, while and for loops check the condition first.

Test
Q.15 Easy C Programming
What will be the memory size occupied by: int arr[5][3];?
A 15 bytes
B 60 bytes
C 30 bytes
D Depends on the compiler
Correct Answer:  B. 60 bytes
EXPLANATION

The array has 5 rows and 3 columns, so total elements = 5 × 3 = 15 elements. Each int typically occupies 4 bytes. Total memory = 15 × 4 = 60 bytes (assuming sizeof(int) = 4 bytes on most systems).

Test
Q.16 Easy C Programming
Which of the following correctly declares a 2D array in C?
A int arr[3][4];
B int arr(3,4);
C int arr;
D int arr{3,4};
Correct Answer:  A. int arr[3][4];
EXPLANATION

A 2D array in C is declared using the syntax: datatype arrayName[rows][columns]. So 'int arr[3][4];' creates a 2D array with 3 rows and 4 columns.

Test
Q.17 Easy C Programming
Which of the following is true about the 'break' statement in C?
A It skips the current iteration
B It exits the loop or switch statement
C It terminates the program
D It has no effect in loops
Correct Answer:  B. It exits the loop or switch statement
EXPLANATION

The 'break' statement is used to exit or terminate a loop or switch statement immediately. It transfers control to the statement following the loop or switch.

Test
Q.18 Easy C Programming
In C, what is the difference between single quotes and double quotes?
A No difference, they are interchangeable
B Single quotes are for characters, double quotes are for strings
C Single quotes for strings, double quotes for characters
D Single quotes cannot be used in C
Correct Answer:  B. Single quotes are for characters, double quotes are for strings
EXPLANATION

In C, single quotes (') are used for single character constants (char type), while double quotes (") are used for string literals (array of characters ending with null terminator).

Test
Q.19 Easy C Programming
Which of the following is NOT a valid identifier in C?
A _variable123
B 123_variable
C variable_123
D Variable_123
Correct Answer:  B. 123_variable
EXPLANATION

In C, an identifier cannot start with a digit. It must start with a letter (a-z, A-Z) or underscore (_). Option B violates this rule by starting with a digit.

Test
Q.20 Easy C Programming
Which of the following correctly initializes a 2D array in C?
A int arr[3][3] = {{1,2,3}, {4,5,6}, {7,8,9}};
B int arr[][3] = {1,2,3,4,5,6,7,8,9};
C Both A and B are correct
D Neither A nor B is correct
Correct Answer:  C. Both A and B are correct
EXPLANATION

Both syntaxes are valid in C. Option A explicitly specifies both dimensions, while Option B lets the compiler calculate the first dimension based on initialization.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips