注册 登录
编程论坛 C++教室

变量也疯狂!!!!!!!!!

yyblackyy 发布于 2010-04-01 11:44, 579 次点击
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{     
    int a=1,b=2,c=3,d=4,e=5,f,*g,*h;
    cout<<"正常的"<<endl;
    h=&a;
    cout<<"a="<<*h<<endl;
    h=&b;
    cout<<"b="<<*h<<endl;
    h=&c;
    cout<<"c="<<*h<<endl;
    h=&d;
    cout<<"d="<<*h<<endl;
    h=&e;
    cout<<"e="<<*h<<endl;
    cout<<"****************************************"<<endl;
    cout<<"无语的变量"<<endl;
    cout<<"a="<<*(&f+5)<<endl;
    cout<<"b="<<*(&f+4)<<endl;
    cout<<"c="<<*(&f+3)<<endl;
    cout<<"d="<<*(&f+2)<<endl;
    cout<<"e="<<*(&f+1)<<endl;
    cout<<"*****************************************"<<endl;
    cout<<"无语的指针"<<endl;
    printf("a=%-d\nb=%-d\nc=%-d\nd=%-d\ne=%-d\n",*(&g+6),*(&g+5),*(&g+4),*(&g+3),*(&g+2));
   
    return 0;
}
/* 知道了变量的声明就。。。。。。。。。。。。无语啊
变量先声明先分配,分配地址从高到低,数组先低再高
一点心得,*/
6 回复
#2
teng1997532010-04-01 14:15
我看不懂...我都不知道什么是C++
#3
apull2010-04-01 14:28
我觉得这个应该跟系统和编译器有关系。。
#4
yyblackyy2010-04-01 14:38
是跟内存变量分配地址有关的刚刚发现感觉有点好玩,呵呵
#5
one_june2010-04-01 17:42
lz c和c++ 混着用...
强人啊...
#6
zyc199111092010-04-01 22:22
输出“无语的变量”后就出现debug error
怎么回事啊
#7
yyblackyy2010-04-01 22:27
正常的
a=1
b=2
c=3
d=4
e=5
****************************************
无语的变量
a=1
b=2
c=3
d=4
e=5
*****************************************
无语的指针
a=1
b=2
c=3
d=4
e=5
Press any key to continue
这是输出结果,我是用VC6 编的
1