Teaching UGC NET Mock Test Series 2025 (Paper 1 & 2) Programming and Data Structure Programming in C Call By Reference
Consider the following two C++ programs P1 and P2 and two statements S1 and S2 about the programs:
|
P1 |
P2 |
|
void f(int a, int*b, int &c) { a = 1; *b =2; c = 3; } int main () { int i = 0; f(i, &i, i): cout ≪ i; } |
double a = 1, b =2; double &f(double &d) { d = 4; return b; } int main () { f(a) = 5; cout ≪ a ≪ “:” ≪b; } |
S1: P1 prints out 3
S2: P2 prints out 4:2
What can you say about the statement S1 and S2?
1
Neither S1 nor S2 is true
2
Only S1 is true
3
Only S2 is true
4
Both S1 and S2 are true