Some stack of order


(2007-10-08 21:17:32)
 

#include <stdio.h>
#include <iostream>
using namespace std;
struct A
{
 int a;
 int b;
 int c;
};
void fun(int i, float f, double d)
{
 int a = 1;
 int b = 2;
 cout << &d << endl;
 cout << &f << endl;
 cout << &i << endl;
 cout << &a << endl;
 cout << &b << endl;
}
int main(void)
{

 int i = 100;
 char c = 'a';
 float f = 5.0;
 double d = 5.0;
 bool b = true;
 int *pI = &i;
 int **ppI = &pI;
 cout << &i << endl;
 printf("%p/n", &c);
 cout << &f << endl;
 cout << &d << endl;
 cout << &b << endl;
 cout << &pI << endl;
 cout << &ppI << endl;
 cout << endl;
/*
地址: 0013FF7C
  0013FF78
  0013FF74
  0013FF6C
  0013FF68
  0013FF64
  0013FF60 
*/
 fun(i, f, d);
/*
地址: 0013FEE8
  0013FEE4
  0013FEE0
  0013FED4
  0013FED0
*/
 cout << endl;
 int a[5] = {1, 2, 3, 4, 5};
 int m = 7;
 cout << a << endl;
 cout << &a[0] << endl;
 cout << &a[1] << endl;
 cout << &a[2] << endl;
 cout << &a[3] << endl;
 cout << &m << endl;
 cout << endl;
/*
地址: 0013FF4C
  0013FF4C
  0013FF50
  0013FF54
  0013FF58
  0013FF48
*/
 cout << endl;
 char s[] = "123456789"; //10
 char p[] = "123";  // 8
 cout << sizeof(s) << endl;
 cout << sizeof(d) << endl;
 printf("%p/n", &s[0]);
 printf("%p/n", &s[1]);
 printf("%p/n", &s[2]);
 printf("%p/n", &s[3]);
 printf("%p/n", &s[4]);
 printf("%p/n", &s[5]);
 printf("%p/n", &s[6]);
 printf("%p/n", &s[7]);
 printf("%p/n", &s[8]);
 printf("%p/n", &s[9]);
 cout << endl;
 printf("%p/n", &p[0]);
 printf("%p/n", &p[1]);
 printf("%p/n", &p[2]);
 printf("%p/n", &p[3]);
 cout << endl;
/*
地址: &s[0] ~ &s[9]
  0013FF3C....0013FF45
  &p[0] ~ &p[4]
  0013FF38...0013FF3B
*/
 struct A n;
 cout << &n.a << endl;
 cout << &n.b << endl;* /    0013FF44   0013FF40Address: 0013FF3C/ *  COUT << endl;
 << endl << & N.C. COUT;






 0 return;
}
/ *
 the stack is extended from higher to lower addresses of
1. Common variables as variable declaration order stack, i.e. the high order address to the lower address of each sound stored variables
2. The function is called from the parameter right to left successively stack
3. the array may be arranged in the internal address and internet related, but generally from the lower address to the high order address storage members each
data member classes and 4. the first statement inside the structure will be subjected to high or low address address, entirely determined by the compiler implementation
, and generally applied "according to a statement from the low order address in order to store individual members to higher addresses."
* /

5. RISC (Reduced Instruction Set Computer) CPU, such as SPARC, PowerPC, etc., the basic data memory type variable high low and high bytes in the address store, the low byte of the high word and low address stored Big Endian format is stored, and the high byte of the address as the first address of the variable.

    AMD, Intel series CPU uses Little Endian storage format to store basic types of variables, namely the low byte of low word and put in a low address, high byte stored in high and high word address, and the lowest byte address as variables the first address.

Reproduced in: https: //my.oschina.net/dake/blog/196847

Guess you like

Origin blog.csdn.net/weixin_34387468/article/details/91586174