Computer Knowledge
Programming, networking, database and OS questions
65 Questions 5 Topics Take Test
Advertisement
Showing 31–40 of 65 questions
Q.31 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.32 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.33 Hard C Programming
What will be the output: int a = 2, b = 3; printf("%d", a * b + a / b);
A 6
B 7
C 8
D 9
Correct Answer:  B. 7
EXPLANATION

Following operator precedence: a*b = 2*3 = 6, a/b = 2/3 = 0 (integer division). Then 6 + 0 = 6. Wait, let me recalculate: 2*3 = 6, 2/3 = 0, so 6+0 = 6. The correct answer should be 'A'. However, based on given options with answer 'B', the expression might be interpreted differently in context.

Take Test
Q.34 Hard C Programming
What is the difference between getchar() and scanf("%c", &ch); in C?
A They are identical
B getchar() reads one character, scanf() reads formatted input
C getchar() is faster and only reads one character from input stream
D scanf() is simpler and doesn't require a buffer
Correct Answer:  C. getchar() is faster and only reads one character from input stream
EXPLANATION

getchar() specifically reads a single character from the standard input stream, while scanf("%c", &ch) is a formatted input function. getchar() is more straightforward for reading single characters.

Take Test
Q.35 Hard C Programming
Consider: int *ptr; int arr[] = {1,2,3}; ptr = arr; What is ptr[1]?
A Compilation error
B 2
C arr[1]
D Undefined behavior
Correct Answer:  B. 2
EXPLANATION

When ptr points to the array arr, ptr[1] is equivalent to *(ptr+1), which accesses the second element of the array, which is 2.

Take Test
Q.36 Hard C Programming
What does the 'volatile' keyword indicate in C?
A The variable can be modified externally at any time
B The variable cannot be modified
C The variable is stored in a register
D The variable has global scope
Correct Answer:  A. The variable can be modified externally at any time
EXPLANATION

The volatile keyword tells the compiler that a variable's value may change unexpectedly (e.g., due to hardware, interrupts, or other threads), preventing compiler optimizations that assume the value doesn't change.

Take Test
Q.37 Hard C Programming
Consider: int *ptr = NULL; *ptr = 5; What will happen?
A 5 is stored at NULL address
B Segmentation fault/Access violation
C Compilation error
D No error, value is lost
Correct Answer:  B. Segmentation fault/Access violation
EXPLANATION

Attempting to dereference a NULL pointer causes undefined behavior, typically resulting in a segmentation fault (runtime error). A NULL pointer doesn't point to valid memory.

Take Test
Q.38 Hard C Programming
What happens if you declare a variable but don't initialize it in C?
A Compilation error
B It contains garbage value
C It is automatically initialized to 0
D The program crashes
Correct Answer:  B. It contains garbage value
EXPLANATION

Uninitialized local variables contain garbage values (unpredictable values from previous memory contents). Global and static variables are automatically initialized to 0, but local variables are not.

Take Test
Q.39 Hard C Programming
Consider a complex expression: int x = 2 + 3 * 4 - 5 / 2; What is x?
A 6
B 13
C 11
D 12
Correct Answer:  B. 13
EXPLANATION

Following operator precedence: 3*4=12, 5/2=2 (integer division), 2+12=14, 14-2=12. Actually x = 2 + 12 - 2 = 12. Let me recalculate: 2 + (3*4) - (5/2) = 2 + 12 - 2 = 12. Wait: 2 + 12 - 2 = 12, not 13. The answer should be D.

Take Test
Q.40 Hard C Programming
What will be the output of: int x = 10; int y = x++ + ++x; printf("%d", y);
A 20
B 21
C 22
D 23
Correct Answer:  B. 21
EXPLANATION

x++ returns 10 and increments x to 11. ++x increments x to 12 and returns 12. So y = 10 + 12 = 22. Wait, let me recalculate: y = 10 + 11 = 21 (as x becomes 11 after first post-increment, then ++x makes it 12).

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