ProgrammingHardProduct-company placement · GATE CS

What is printed (C++17)?

What is printed (C++17)?
int a[] = {1, 2, 3, 4};
int* p = a + 1;
cout << *p++;
cout << *++p;
cout << p[-1];
  1. A. 343
  2. B. 233
  3. C. 244
  4. D. 243

Correct answer: D. 243

*p++ dereferences the old pointer (a[1] = 2) and then advances p to a + 2. *++p advances to a + 3 first and prints 4. p[-1] is a[2] = 3.

More OOP with C++ and Java questions

Exams that ask this topic