Why are we only allowed to declare and define variables in global section?Why not include assignment in global section?
Example:
#include<stdio.h>
int a;
a=5;//Valid because its similar to int a=5; Therefore a initialiser to a Tentative definition
a=8;//Invalid because We can have only one initialiser for a tentative definition
void main(){
...
}
Why do we need this? What would be the consequences if we were allowed to have more than one initializer to a tentative definition
My next question is why only constant initializer elements are allowed?
#include<stdio.h>
int i=5;
int j=i+5;//[Error] initializer element is not constant
void main(){
...
}
Similarly what would be the consequences we face if this rule was not present?
Please note my question is not exactly why this happens? I'm trying to figure why these restrictions were given in the first place.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…