What will be printed out as a result of the following code's execution?
#include "stdio.h"

int main() {
    int * param1 = new int(2);
    int param2 = 2;
    int * reference = &param2;
    printf("%d", *reference == *param1);
    return 0;
}
Explanation
The following line creates pointer param1 to int variable, which has value 2:
int * param1 = new int(2);
reference is now pointing to the param2 and contains it's address.
int * reference = &param2;
When comparing, we use dereference operator (*) to access the real values, not addresses, therefore result is true. Since printf function prints result as decimal integer value ("%d"), 1 is written in output.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести