Q:

Using pointers, write a function to swap the values of two ints. Test the function by calling it and printing the swapped values

0

Using pointers, write a function to swap the values of two ints. Test the function by calling it and printing the swapped values.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>

void swapInt(int *a, int *b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

int main() {
  int a, b;
  std::cin >> a >> b;
  swapInt(&a, &b);
  std::cout << a << " " << b << std::endl;

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now