static关键字

来源:互联网 发布:java面试题2016 编辑:程序博客网 时间:2024/05/17 08:37
his is my code what i writted for the Comprehensive quiz. After i was done with it and tested that it works ( and it worked as it needed ) i checked out the solution but sawed that i do did it in an other way. I want you if you have some time that to check down the code and what do you think about it.Im totally new in this C++ programming, started with your tutorial just a few days ago but i learned java in scool so probably its recogniseable in my codeing :D .#include#includeusing namespace std;int main(){double nNumberOne = 0;double nNumberTwo = 0;char nSymbol;double nEredmeny = 0;cout <> nNumberOne ;cout <> nNumberTwo ;cout <> nSymbol;if (nSymbol == ‘+’ ){nEredmeny = nNumberOne + nNumberTwo;cout << nNumberOne <<" + " << nNumberTwo << " = " << nEredmeny;}if (nSymbol == '-' ){nEredmeny = nNumberOne – nNumberTwo;cout << nNumberOne <<" – " << nNumberTwo << " = " << nEredmeny;}if (nSymbol == '*' ){nEredmeny = nNumberOne * nNumberTwo;cout << nNumberOne <<" * " << nNumberTwo << " = " << nEredmeny;}if (nSymbol == '/'){nEredmeny = nNumberOne / nNumberTwo;cout << nNumberOne <<" / " << nNumberTwo << " = " << nEredmeny;

在前人的经验教训,你了解了局部变量(有块范围)和全局变量(有计划的范围)。还有另一个作用域的变量,可以水平:文件范围

文件范围内的变量可以被访问的任何功能或嵌在一个单一的文件。申报文件作用域的变量简单地声明一个变量,块外(同一个全局变量)使用static关键字

1
2
3
4
5
6
7
staticint nValue; // file scoped variable
floatfValue; // global variable
 
intmain()
{
    doubledValue; // local variable
}

0 0
原创粉丝点击