What will be printed out as a result of program execution?
#include <iostream>

using namespace std;

void init(int *x)
    x = new int;
    *x = 50;

int main()
    int v = 100;
    cout << v;

    return 0;
Since the pointer is passed to the void init (int *x) function by value, it points to another memory location where number 50 is written after its change in the line x = new int. As a result, the memory allocated by the init function leaks and 100 is displayed on the screen.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Зарегистрируйся сейчас
или Подпишись на будущие тесты