Home Subjects Computer Knowledge

Computer Knowledge

Programming, networking, database and OS questions

309 Q 2 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 141–150 of 309
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.141 Hard C Programming
What is the difference between a function declaration and a function definition in C?
A Declaration provides the function signature; definition provides the implementation
B They are the same thing
C Declaration is optional; definition is mandatory
D Definition must appear before declaration
Correct Answer:  A. Declaration provides the function signature; definition provides the implementation
EXPLANATION

A function declaration (or prototype) tells the compiler about the function's name, return type, and parameters. A function definition includes the declaration along with the function body containing the actual implementation. Declaration is optional if the function is defined before use.

Take Test
Q.142 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.

Take Test
Q.143 Medium C Programming
What is the output of the expression: 10 / 3 * 3 in C?
A 10
B 9
C 3.33
D Cannot be determined
Correct Answer:  B. 9
EXPLANATION

Division and multiplication have the same precedence and are evaluated left-to-right. Step 1: 10 / 3 = 3 (integer division). Step 2: 3 * 3 = 9. Therefore, the result is 9.

Take Test
Q.144 Hard C Programming
Which of the following correctly describes the relationship between arrays and pointers in C?
A Arrays and pointers are identical
B An array name decays to a pointer to its first element
C Pointers can only be used with dynamically allocated arrays
D Arrays are pointers stored on the stack
Correct Answer:  B. An array name decays to a pointer to its first element
EXPLANATION

In C, when an array name is used in most contexts, it decays (converts) to a pointer to its first element. For example, in int arr[5];, arr behaves like &arr[0]. However, arrays and pointers are not identical; arrays have fixed size while pointers are variables.

Take Test
Q.145 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.
Take Test
Q.146 Medium C Programming
Which of the following is a correct way to initialize a pointer to NULL?
A int *ptr = 0;
B int *ptr = NULL;
C int *ptr = (void*)0;
D All of the above
Correct Answer:  D. All of the above
EXPLANATION

All three methods are correct ways to initialize a pointer to NULL. 0, NULL, and (void*)0 all represent a null pointer. NULL is typically a macro defined as 0 or ((void*)0) in the standard library.

Take Test
Q.147 Medium C Programming
How many times will the following loop execute: for(int i=0; i
A 2 times
B 3 times
C 4 times
D 5 times
Correct Answer:  B. 3 times
EXPLANATION

The loop executes for i=0, i=1, and i=2. When i=3, the break statement is encountered, which immediately terminates the loop. Therefore, the loop executes exactly 3 times.

Take Test
Q.148 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.

Take Test
Q.149 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.

Take Test
Q.150 Medium C Programming
What is the correct way to declare a constant in C?
A constant int x = 10;
B const int x = 10;
C int const x = 10;
D Both B and C
Correct Answer:  D. Both B and C
EXPLANATION

Both 'const int x = 10;' and 'int const x = 10;' are valid ways to declare a constant in C. The const keyword can be placed before or after the type specifier, and both have the same meaning.

Take Test
IGET
iget AI
Online · Ask anything about exams
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