102k views
5 votes
Given the function definition

void something(int a, int* b)
{
inc;
c = a + 2;
a = a * 3;
*b = c + a
}
what is the output after the following code fragment that invokes something
int r = 1;
int s = 2;
int t = 3;
printf(""%d %d %d\\"", r, s, t);
A) 1 10 3
B) 1 14 3
C) 1 14 9
D) 5 14 3

User Sreeraj VR
by
7.8k points

1 Answer

5 votes

Final answer:

When the code fragment is executed, the output will be 1 8 3.

Step-by-step explanation:

The given function definition is:

void something(int a, int* b) {
inc;
c = a + 2;
a = a * 3;
*b = c + a;
}

When the code fragment is executed:

  1. The variable r is initialized to 1.
  2. The variable s is initialized to 2.
  3. The variable t is initialized to 3.
  4. The something function is called, passing r and the address of s.
  5. Inside the something function, a is multiplied by 3, resulting in 3, c is assigned the value of a + 2, resulting in 5, and the value of *b (which is s) is assigned the value of a + c, resulting in 8.
  6. The values of r, s, and t are printed.

Therefore, the output will be 1 8 3.

User TimSum
by
9.3k points