变量和算术运算之算术运算(一)

#include<iostream>
usingnamespace std;
int main()
{
       
int i,j,k,p,m,n;
       
double a,b,c,d,e,f,g,h,x,y,z;


        i
=5;
        j
=5;
        k
=11;
        p
=3;
        x
=3.0;
        y
=4.0;
        cout
<<"---------Section 1 output"
               
"-------"<<endl<<endl;


        a
=x+y;
        b
=x-y;
        c
=x*y;
        d
=x/y;
        e
=d+3.0;
        f
=d+3;
        i
=i+1;
        j
=j+1;//注意,这些赋值语句右边的变量必须已经赋值。当未初始化的变量出现在赋值语句的右边时,编译不会出错,但程序会带着错误继续运行。


        cout
<<"a="<<a<<"\t  b="<<b<<"\t  c="<<c<<"\t  d="<<d<<endl;
        cout
<<"e="<<e<<"\t  f="<<f<<"\t  i="<<i<<"\t  j="<<j<<endl;

        cout
<<"\n\n----------Section 2 output"
               
"-----------"<<endl<<endl;


        m
=k%p;
        n
=p%k;
        i
++;
       
++j;
        e
--;
       
--f;
        cout
<<"m="<<m<<"\t n="<<n<<"\t  i="<<i<<"\t j="<<j<<endl;
        cout
<<"e="<<e<<"\t f="<<f<<endl<<endl;

        x
=y+z;
        cout
<<"With z not initialized,x=y+z="<<x<<endl<<endl;

        i
=32770;
        cout
<<"i="<<i<<endl;
       
return0;
}
/*超出整数范围:当整数类型变量超出范围时,编译不会出错,继续运行,此时变量如同指针划过一般继续滑到指定的位置赋值。*/
posted @ 2012-06-21 16:11  蚂蚁踩死了大象  阅读(91)  评论(0)    收藏  举报