What is the output of following program?
# include <stdio.h> void fun(int x) { x = 30; } int main() { int y = 20; fun(y); printf("%d", y); return 0; } |
(A) 30
(B) 20
(C) Compiler Error
(D) Runtime Error
Answer: (B)
Explanation: Parameters are always passed by value in C. Therefore, in the above code, value of y is not modified using the function fun(). So how do we modify the value of a local variable of a function inside another function. Pointer is the solution to such problems. Using pointers, we can modify a local variable of a function inside another function. See the next question.
Note that everything is passed by value in C. We only get the effect of pass by reference using pointers.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- C | Pointer Basics | Question 2
- C | Pointer Basics | Question 7
- C | Pointer Basics | Question 4
- C | Pointer Basics | Question 3
- C | Pointer Basics | Question 11
- C | Pointer Basics | Question 12
- C | Pointer Basics | Question 15
- C | Pointer Basics | Question 17
- C | Pointer Basics | Question 16
- C | Pointer Basics | Question 17
- C | Pointer Basics | Question 17
- C | Pointer Basics | Question 14
- C | Pointer Basics | Question 8
- C | Pointer Basics | Question 6
- C | Pointer Basics | Question 10
- C | Pointer Basics | Question 13
- Double Pointer (Pointer to Pointer) in C
- C++ | this pointer | Question 5
- C++ | this pointer | Question 4
- C++ | this pointer | Question 1

