Skip to content

UGC NET CS 2018Programming Languages and Computer Graphics › Programming in C++Verified

UGC NET CS 2018 PYQ: Consider the following two $C++$ programs $P1$ and $P2$ and two statements $S1$ and $S2$ about these…

Consider the following two $C++$ programs $P1$ and $P2$ and two statements $S1$ and $S2$ about these 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);

count <<i;

}

double a=1, b=2;

double &f(double &d)

{

d=4;

return b;

}

int main()

{

f(a)=5;

count < < a< < “:” < < b;

}

$S1$ : $P1$ prints out $3.$

$S2$ : $P2$ prints out $4:2$

What can you say about the statements $S1$ and $S2$?

$Code:$

  1. A
    Only $S1$ is true
    Correct answer
  2. B
    Only $S2$ is true
  3. C
    Both $S1$ and $S2$ are true
  4. D
    Neither $S1$ nor $S2$ is true

Answer

(A) Only $S1$ is true

Approach

Trace pass-by-value, pointer and reference parameter behaviour in each program.

Reviewed by UGC IQ Editorial Team.