Simple(!) problem

Whats the difference between these two?
Discussion in details will be much helpful for me...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;

int a,b, sum;

int main()
{
    cin>>a>>b;
    sum=a+b;
    cout<<sum;
    cout<<endl;
     
    system ("Pause");
    return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;

int main()
{
    int a,b, sum;
    cin>>a>>b;
    sum=a+b;
    cout<<sum;
    cout<<endl;
     
    system ("Pause");
    return 0;
}


Last edited on
There are three difference: 1) storage duration ; 2) scope 3) and linkage of variables.

In the first example variables a, b, sum have static storage duration and are zero initialized. They have the global scope and external linkage.
In the second example these varaibles have automatic storage duration, have undefined values and the block scope. They have no linkage.
Topic archived. No new replies allowed.