Multiple choice technology programming languages

What does the following do: 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. Undefined

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

In main, v is initialized to 10. Its address is passed to afunction. Inside afunction, the local pointer parameter x is reassigned to point to a newly allocated memory address, leaving the original variable v in main completely unmodified. Thus, v remains 10.