Computer scienceProgramming languagesC++Operators and expressions

Increment and decrement operators

Print the output

Report a typo

What will be the output of the following code?

Avoid using compilers to generate the output. Try to solve on pen and paper or dry run the code yourself
#include <iostream>

int main() {
    int num = 15;
    
    int result1 = num++; 
    
    int result2 = ++num; 

    std::cout << num << "\n";
    std::cout << result1 << "\n";
    std::cout << result2 << "\n";

 
    int result3 = num--; 
    
    int result4 = --num; 
    
    std::cout << num << "\n";
    std::cout << result3 << "\n";
    std::cout  << result4 << "\n";

    return 0;
}
Select one option from the list

Create a free account to access the full topic