We know that in C ++, the storage area of global variables and local variables is different. The global variables are stored in static data areas and local variables are stored in the stack area. However, there is another small point that is stored in the static data area. The variables stored in the stack area are stored from high addresses to the low address. Static local variables and static global variables.
#include <iOSTREAM>
using namespace std;
int allval1 = 3, allval2 = 4; // global variables
Static int Sallval1 = 2, Sallval2 = 5; // Static global variables
main (main (main (main (main (main (main (main
{{
Static int SVAL1 = 2, SVAL2 = 3; // Static local variables
int Val1 = 0, Val2 = 1;
COUT << "Storage order of global variables:" << endl;
COUT << "allval1:" << & allVal1 << "allval2:" << & allVal2 << endl;
COUT << "Storage order of static global variables:" << endl;
COUT << "Sallval1:" << & SALLVAL1 << "Sallval2:" << & Sallval2 << Endl;
COUT << "Storage order of static local variables:" << endl;
COUT << "SVAL1:" << & SVAL1 <"" SVAL2: "<< & SVAL2 << Endl;
COUT << "Storage order of local variables:" << endl;
COUT << Val1: "<< & Val1 <<" Val2: "<< & Val2 << endl;
}