Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

490 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 231–240 of 490
Topics in C Programming
Q.231 Medium Pointers
What will be the output?
int a[] = {10, 20, 30};
int *p = a;
printf("%d", *(p+2));
A 10
B 20
C 30
D Garbage value
Correct Answer:  C. 30
EXPLANATION

p points to a[0], p+2 points to a[2] which contains 30. Dereferencing gives 30.

Test
Q.232 Medium Pointers
What is the difference between pointer and array name in C?
A No difference, both are same
B Array name is a pointer constant, cannot be modified
C Pointer can store any address, array name stores only array address
D Arrays are faster than pointers
Correct Answer:  B. Array name is a pointer constant, cannot be modified
EXPLANATION

Array names are pointer constants that point to the first element and cannot be reassigned, while pointer variables can be modified to point to different addresses.

Test
Q.233 Medium Pointers
What will be the output of: int x = 10; int *p = &x; printf("%p", p); (assuming typical system output)
A 10
B A memory address in hexadecimal format
C The size of integer
D Error: invalid format specifier
Correct Answer:  B. A memory address in hexadecimal format
EXPLANATION

The %p format specifier prints the pointer value as a memory address in hexadecimal format, not the dereferenced value.

Test
Q.234 Medium Pointers
Consider: void func(int *arr, int size); This function prototype suggests that func will:
A Create a new array inside the function
B Modify the original array passed from the caller
C Only read the array values
D Return the array to the caller
Correct Answer:  B. Modify the original array passed from the caller
EXPLANATION

Since an array pointer is passed, the function can access and modify the original array elements in the caller's scope.

Test
Q.235 Medium Pointers
A function needs to modify a variable in the calling function. Which parameter passing method is appropriate?
A Pass by value
B Pass by reference using pointers
C Pass by global variable
D None of the above
Correct Answer:  B. Pass by reference using pointers
EXPLANATION

To modify a variable in the calling function, you must pass its address (pointer). Pass by value creates a copy and cannot modify the original.

Test
Q.236 Medium Pointers
Consider: int arr[5] = {1, 2, 3, 4, 5}; int *p = arr; What is the value of *(p+2)?
A 2
B 3
C 4
D 5
Correct Answer:  B. 3
EXPLANATION

p points to arr[0]. p+2 points to arr[2], and *(p+2) dereferences to the value at arr[2], which is 3.

Test
Q.237 Medium Pointers
Which memory allocation function does NOT initialize allocated memory to zero?
A calloc()
B malloc()
C realloc()
D Both B and C
Correct Answer:  D. Both B and C
EXPLANATION

malloc() and realloc() return uninitialized memory with garbage values. calloc() initializes all bytes to zero.

Test
Q.238 Medium Pointers
Consider: int x = 5; int *p = &x; int **q = &p; What is the value of **q?
A 5
B Address of p
C Address of x
D Error
Correct Answer:  A. 5
EXPLANATION

q is a pointer to pointer p. **q dereferences twice: first to get p, then to get the value x, which is 5.

Test
Q.239 Medium Pointers
Which of the following best describes a dangling pointer situation?
A A pointer that points to a valid memory location
B A pointer that points to memory that has been freed or deallocated
C A pointer that has not been initialized
D A pointer used in arithmetic operations
Correct Answer:  B. A pointer that points to memory that has been freed or deallocated
EXPLANATION

A dangling pointer occurs when it points to memory that no longer exists, typically after free() or when a local variable goes out of scope.

Test
Q.240 Medium Pointers
Consider the code: int arr[] = {5, 10, 15, 20}; int *ptr = arr; ptr++; What does ptr now point to?
A The value 5
B The value 10
C The address of arr[1]
D The address increased by 1 byte
Correct Answer:  C. The address of arr[1]
EXPLANATION

Pointer arithmetic increments by the size of the data type. For int (4 bytes), ptr++ moves to the next integer, which is arr[1].

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