Home Subjects Computer Knowledge C Programming

Computer Knowledge
C Programming

Programming, networking, database and OS questions

96 Q 2 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 81–90 of 96
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.81 Medium C Programming
What is the correct way to declare a function that takes no parameters and returns an integer?
A int func();
B int func(void);
C func() returns int;
D int func(no parameters);
Correct Answer:  B. int func(void);
EXPLANATION

To explicitly declare a function with no parameters in C, use 'void' as the parameter. int func(); is ambiguous in older C standards.

Test
Q.82 Medium C Programming
In C, what is the purpose of the #define directive?
A To define functions
B To define macros or constants
C To declare variables
D To include header files
Correct Answer:  B. To define macros or constants
EXPLANATION

#define is a preprocessor directive used to define symbolic constants (macros) and performs text substitution before compilation.

Test
Q.83 Medium C Programming
Which of the following is used to access members of a structure using a pointer?
A Dot operator (.)
B Arrow operator (->)
C Ampersand (&)
D Asterisk (*)
Correct Answer:  B. Arrow operator (->)
EXPLANATION

The arrow operator (->) is used to access structure members through a pointer. The dot operator (.) is used for direct access.

Test
Q.84 Medium C Programming
What does the break statement do in a loop?
A Skips the current iteration
B Terminates the loop immediately
C Pauses the loop
D Restarts the loop
Correct Answer:  B. Terminates the loop immediately
EXPLANATION

The break statement immediately terminates the loop and transfers control to the statement following the loop.

Test
Q.85 Medium C Programming
What is the default return type of a function in C if not explicitly specified?
A void
B int
C char
D float
Correct Answer:  B. int
EXPLANATION

In C, if a function's return type is not explicitly specified, it defaults to int. However, modern C standards require explicit return type declaration.

Test
Q.86 Medium C Programming
Which of the following correctly initializes an array of 5 integers?
A int arr[5] = {1, 2, 3, 4, 5};
B int arr(5) = {1, 2, 3, 4, 5};
C int [5] arr = {1, 2, 3, 4, 5};
D int arr[5];
Correct Answer:  A. int arr[5] = {1, 2, 3, 4, 5};
EXPLANATION

Arrays in C are declared with square brackets containing the size, followed by initialization in curly braces. Option A is the correct syntax.

Test
Q.87 Medium C Programming
What is the purpose of the malloc() function in C?
A To deallocate memory
B To allocate memory dynamically at runtime
C To initialize variables
D To declare arrays
Correct Answer:  B. To allocate memory dynamically at runtime
EXPLANATION

malloc() (memory allocation) allocates a block of memory dynamically during program execution and returns a pointer to it.

Test
Q.88 Medium C Programming
In C, a pointer variable stores which of the following?
A The actual value of a variable
B The memory address of a variable
C The size of a variable
D The data type of a variable
Correct Answer:  B. The memory address of a variable
EXPLANATION

A pointer is a variable that stores the memory address of another variable. It is declared using the * symbol.

Test
Q.89 Medium C Programming
What will be the output of the following C code?
int x = 10;
int y = 20;
int z = x < y ? x++ : y++;
printf("%d %d %d", x, y, z);
A 10 20 10
B 11 20 10
C 10 21 20
D 11 21 10
Correct Answer:  B. 11 20 10
EXPLANATION
Step 1: Evaluate condition x < y → 10 < 20 → true. Step 2: Execute true branch: x++ returns 10, then x becomes 11. Step 3: z = 10. Step 4: printf prints x=11, y=20, z=10.
Test
Q.90 Medium C Programming
Which of the following correctly describes the scope of a static variable declared inside a function?
A Local to the function, retains value between function calls
B Global scope, initialized once
C Local to the file only
D Creates a new instance on each function call
Correct Answer:  A. Local to the function, retains value between function calls
EXPLANATION

A static variable declared inside a function has local scope (visible only within that function) but persists for the entire program lifetime. Its value is retained between function calls and is initialized only once.

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