Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

1,000 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 411–420 of 1,000
Topics in C Programming
Q.411 Hard Pointers
What is the relationship between arrays and pointers?
A Arrays are pointers
B Pointers are arrays
C Array name decays to pointer in most contexts
D They are unrelated
Correct Answer:  C. Array name decays to pointer in most contexts
EXPLANATION

Array name acts as pointer to first element in expressions but they're distinct. &arr and arr differ in type.

Test
Q.412 Hard Pointers
For dynamic 2D array: int **arr = (int**)malloc(n * sizeof(int*)); What's missing?
A Nothing, code is complete
B Allocating memory for each row
C Casting malloc result
D Type checking
Correct Answer:  B. Allocating memory for each row
EXPLANATION

This allocates row pointers only. Each row needs allocation: arr[i] = (int*)malloc(m * sizeof(int));

Test
Q.413 Hard Pointers
What is the output of: printf("%p", NULL);?
A 0x0
B NULL
C Implementation-defined (typically 0x0 or empty)
D Compilation error
Correct Answer:  C. Implementation-defined (typically 0x0 or empty)
EXPLANATION

%p prints pointer values. NULL representation depends on implementation, commonly shown as 0x0 or (nil).

Test
Q.414 Medium Pointers
In: int *p; *p = 10; What is the issue?
A Syntax error
B p is uninitialized (wild pointer)
C Memory leak
D Type mismatch
Correct Answer:  B. p is uninitialized (wild pointer)
EXPLANATION

p is not initialized to valid address. Dereferencing causes undefined behavior (writing to random memory location).

Test
Q.415 Medium Pointers
Which of the following is valid pointer comparison?
A p > 5
B p == q (different types)
C p < q (valid pointers)
D p + 10
Correct Answer:  C. p < q (valid pointers)
EXPLANATION

Pointers of same type can be compared using <, >, ==, !=. Comparing with integers or different types is invalid.

Test
Q.416 Easy Pointers
What happens with: int arr[10]; int *p = arr; *p = 5; printf("%d", arr[0]);?
A Prints garbage
B Prints 5
C Compiler error
D Prints 10
Correct Answer:  B. Prints 5
EXPLANATION

p points to arr[0]. *p = 5 modifies arr[0]. Printing arr[0] displays 5.

Test
Q.417 Hard Pointers
In pointer to function: int (*ptr)(int, int); What does this declare?
A Function returning pointer to int
B Pointer to function returning int with 2 int parameters
C Array of pointers
D Pointer to array of ints
Correct Answer:  B. Pointer to function returning int with 2 int parameters
EXPLANATION

Parentheses around *ptr give pointer priority. It's a pointer to a function taking 2 ints and returning int.

Test
Q.418 Easy Pointers
What is the result of: int x = 5; int *p = &x; int *q = p; if p == q?
A 0 (false)
B 1 (true)
C Undefined
D Compiler error
Correct Answer:  B. 1 (true)
EXPLANATION

Both p and q point to same address of x, so p == q evaluates to true (1).

Test
Q.419 Medium Pointers
For function: void modify(int *x) { *x = 20; } If called as modify(&a), what changes?
A The pointer itself
B The value of variable a
C The function parameter
D Nothing
Correct Answer:  B. The value of variable a
EXPLANATION

Passing address allows function to modify original variable. *x = 20 changes the value at that address.

Test
Q.420 Medium Pointers
Which scenario demonstrates a dangling pointer?
A Pointer declared but not initialized
B Pointer freed but still used afterward
C Pointer set to NULL
D Pointer pointing to static variable
Correct Answer:  B. Pointer freed but still used afterward
EXPLANATION

Dangling pointer occurs when memory is freed but pointer still references that location. This causes undefined behavior.

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