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;
These functions work this way:

int preinc(int &x) {
    return x;

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

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Sign Up Now
or Subscribe for future quizzes