Program Crash

hey i took this code to see how my visual studio 2012 will respond
and it crashed i took this code from the documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  // operating with variables

#include <iostream>
using namespace std;

int main ()
{
  // declaring variables:
  int a, b;
  int result;

  // process:
  a = 5;
  b = 2;
  a = a + 1;
  result = a - b;

  // print out the result:
  cout << result;

  // terminate the program:
  return 0;
}
Last edited on
the code shall be compiled and executed successfuly
i know but its not
> and it crashed i took this code from the documentation

Chances are that it did not crash, but finished execution very quickly and exited.

What happens when you add std::cin.get(); just before the return 0;?
exactly. finished execution very quickly and exited but when i add your piece of code
its stayed a=4 b=7 can u explain tom e why its exiting exactly after the program run?
Because it's finished. It gets to the end of the program, and it's over.

Chances are, you're using an IDE that opens a new coommand-line console/terminal for the program, and closes it when the program finishes.

If you want to program to run in a persistent command-line window, then open one and run and the program in that.
some IDEs support two types of execution, one that closes after finish, and a debug mode that pauses the console before the main returns.
if your IDE support such mode, you can use it, otherwise check this:

http://www.cplusplus.com/forum/beginner/103201/

it has lots of good ideas, and some bad ones.
the bad methods are criticized.
Topic archived. No new replies allowed.