Answer to Question #257204 in C++ for tatheer

Question #257204

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. 


1
Expert's answer
2021-10-26T17:28:00-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS