Home > Back-end >  About where the global variable function call is legal?
About where the global variable function call is legal?

Time:04-11

 # include & lt; iostream> 

Int the add (int a, int b)
{
STD: : cout & lt; Return (a + b);
}

Int result1=add (4, 2);


Int main () {
Int result=add (1, 2);
return 0;
}


Int result1=add (4, 2); Is a function of where the global call, not through the main () entry function,
Vaguely remember can't do that, before the function call can't like ordinary variables in a global variable OuZhi or move, but the above code to run is correct, please correct me,

CodePudding user response:

So to write in c + +
Will run in the main initialization before all need very quantity function called global variables

CodePudding user response:

C + +, C language compiler error,
But anyway, so write is not recommended, code maintenance is a disaster,

CodePudding user response:

So write is not recommended.

CodePudding user response:

Look at the code it hurts head want to hit people

CodePudding user response:

Hello, you can probably say why C are not allowed to do it, in addition to maintain trouble, what is the fatal damage?

refer to the second floor 636 f6c696e reply:
C + +, C language compiler error,
But anyway, so write is not recommended, code maintenance is a disaster,

CodePudding user response:

reference 5 floor registercsdn reply:
how do you do, you can probably say why C are not allowed to do it, in addition to maintain trouble, what is the fatal damage?

Quote: refer to the second floor 636 f6c696e reply:

C + +, C language compiler error,
But anyway, so write is not recommended, code maintenance is a disaster,
grammar does not allow
Initialization of static storage with a compile-time constants function call to determine the results until runtime

CodePudding user response:

Run there is no problem, but is not recommended, because the main characteristics of global variables is always across the entire program, its life cycle is not easy to maintain

CodePudding user response:

It is not recommended to do so,,,,

CodePudding user response:

I have a question, if the int result1=add (4, 2); Write the add (4, 2) will be an error, is this why?
  • Related