第五章-程序设计基本概念(1)

来源:互联网 发布:农村淘宝服务站地址 编辑:程序博客网 时间:2024/06/03 12:43

5.1赋值语句

<span style="font-size:14px;">int i = 1;void main(){    int i = i;}</span>
C++中合法,虽然不合理。结果:main()里的i 是一个未定义值。

在函数内部对变量的访问是指对局部变量的访问,也就是说,在函数内部,局部变量与全局变量重名时,全局变量暂时失去作用。

#include <iostream>using namespace std;int main(){     int x = 2,y,z;    x *= (y = z = 5);    cout << x << endl;    z = 3;    x == (y = z);    cout << x << endl;    x = (y == z);    cout << x << endl;    x = (y & z);    cout << x << endl;    x = (y && z);    cout << x << endl;    y =4;    x = (y | z);    cout << x << endl;    x = (y || z);    cout << x << endl;    return 0;}
输出结果 10  ,10 , 1, 3, 1, 7, 1

解析待续


1

0 0
原创粉丝点击