Write a C++ program to create two pointers of integer type, now take values in these pointers and pass them to a function. Function will update both the values by adding “1” to them. Display the updated values in main.
#include <iostream>
void Inc(int *x, int *y) {
++(*x);
++(*y);
}
int main() {
int x = 1, y = 2;
int *pX = &x;
int *pY = &y;
std::cout << *pX << " " << *pY << '\n';
Inc(pX, pY);
std::cout << *pX << " " << *pY << '\n';
return 0;
}
Comments
Leave a comment