zoukankan      html  css  js  c++  java
  • 静态变量在函数中的妙用

    变量a会从运行的程序上叠加,因此输出a++的值为9,10,11,12,13,14等
    #include "stdafx.h"
    #include
    using namespace std;
    int A(){
    static int a=9; //去掉static  程序将会不一样
    cout<< a++<<endl;
    return 0;
    }
    int _tmain(int argc, _TCHAR* argv[])
    {
    for (int i=0;i<10;i++){
    A();
    }
    while(1);
    return 0;
    }
    变量a会从运行的程序上不会叠加,因此输出a++的值全为9
    #include "stdafx.h"
    #include
    using namespace std;
    int A(){
     int a=9;
    cout<< a++<<endl;
    return 0;
    }
    int _tmain(int argc, _TCHAR* argv[])
    {
    for (int i=0;i<10;i++){
    A();
    }
    while(1);
    return 0;
    }
     
    赋值代码自行验证
     
     
     
     
  • 相关阅读:
    JAVA变量的作用域
    SQLite
    ajax
    浏览器调试
    SQL链接
    Computer
    Sql知识点总结
    Web Socket
    秒杀
    副业
  • 原文地址:https://www.cnblogs.com/tangjunjun/p/11676560.html
Copyright © 2011-2022 走看看