After calling C++ function from main function it turns into loop

Problem description:
I have declared a global variable in my c++ program. I have initialized this global variable in my main function. After that I have called another function named f(). In output it turns into a loop and constantly printing value.

Expected behavior:

It should print value just 2 times.

Actual behavior:

It has turned into a loop

Steps to reproduce:

Declare a global variable in c++. Create a function and call from main function.

Bug appears at this link:


Chrome Browser/Windows 10


#include <iostream>

int a = 10;

void f() {
    std::cout << a++ << std::endl;

int main(){
      std::cout << a << std::endl;