#include <iostream> // Define incrementPtr(int* x) // Increment the value pointed to by x // Do nothing if x is nullptr // Define incrementRef(int& x) // Increment the referenced value void incrementPtr(int* x) { // std::cout << "Increment Pointer: " << *x << std::endl; if (x == nullptr) return; *x += 1; } void incrementRef(int& x) { // std::cout << "Increment Ref: " << x << std::endl; x++; } int main() { int n; std::cin >> n; int a{n}; incrementPtr(&a); std::cout << "After incrementPtr: " << a << "\n"; int b{n}; incrementRef(b); std::cout << "After incrementRef: " << b; return 0; }
Test Cases
Test Results
Input
5
Expected Output
After incrementPtr: 6 After incrementRef: 6