C | Advanced Pointer | Question 10
Output of following program
#include <stdio.h> int fun(int arr[]) { arr = arr+1; printf("%d ", arr[0]); } int main(void) { int arr[2] = {10, 20}; fun(arr); printf("%d", arr[0]); return 0; } |
chevron_right
filter_none
(A) Compiler Error
(B) 20 10
(C) 20 20
(D) 10 10
Answer: (B)
Explanation: In C, array parameters are treated as pointers (See https://www.geeksforgeeks.org/why-c-treats-array-parameters-as-pointers/ for details).
So the variable arr represents an array in main(), but a pointer in fun().
Quiz of this Question
Recommended Posts:
- C | Advanced Pointer | Question 3
- C | Advanced Pointer | Question 4
- C | Advanced Pointer | Question 5
- C | Advanced Pointer | Question 2
- C | Advanced Pointer | Question 7
- C | Advanced Pointer | Question 9
- C | Advanced Pointer | Question 1
- C | Advanced Pointer | Question 8
- Double Pointer (Pointer to Pointer) in C
- C++ | this pointer | Question 1
- C++ | this pointer | Question 2
- C++ | this pointer | Question 3
- C++ | this pointer | Question 5
- C++ | this pointer | Question 4
- What is a Pointer to a Null pointer



