Fun with Pointers 2

Consider the following C++ code :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include <bits/stdc++.h>
using namespace std;

int main() {

    int *p, *q;

    int x = 1;

    p = &x;

    *p = 2;

    q = p;

    *q = 3;

    printf("%d\n", *p + *q + x);

    return 0;
}

What will the program outputs?

×

Problem Loading...

Note Loading...

Set Loading...