What is the result of the following code execution?

#include <iostream>

using namespace std;

int preinc(int &x) {
    return ++x;
}

int postinc(int &x) {
    return x++;
}

int main(void) {
    int x = 5;
    cout << preinc(x);
    cout << postinc(x);
    cout << x;
    return 0;
}
Explanation
These functions work this way:

int preinc(int &x) {
    ++x
    return x;
}

int postinc(int &x) {
{
  int temp = x;
  ++x;
  return temp;
}

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback