Multiple choice technology programming languages

What does the following code output? void afunction(int *x) { x=new int; *x=12; } int main() { int v=10; afunction(&v); cout<

  1. Outputs 12

  2. Outputs 10

  3. Outputs the address of v

  4. Compile error

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The function receives a copy of the pointer to v. Inside the function, x is reassigned to a new memory address (new int), so modifying *x only changes the dynamically allocated integer, leaving the original variable v in main unchanged at 10.