Simple(!) problem

Apr 19, 2013 at 2:30pm
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 Apr 19, 2013 at 2:30pm
Apr 19, 2013 at 2:40pm
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.