Which of the following lines correctly declare a function which processes/modifies an input pointer?
void Init(int**  ptr);  //1
void Init(int*   ptr);  //2
void Init(int*& ptr);  //3
void Init(int&* ptr);  //4
  • 1. Correct. The function accepts a pointer to pointer, which, when dereferenced, returns the original pointer we want to modify.
  • 2. Wrong. The function creates a copy of the input variable, in this case - a copy of the input pointer, hence the original input pointer is not modified.
  • 3. There are no pointers to references in C++.
  • 4. Correct. The function accepts a reference to original pointer at input, and is able to modify it.

Слідкуй за CodeGalaxy

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

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