zoukankan      html  css  js  c++  java
  • 内部块-inner blocks ,中的变量

    局部变量只在它所在的块中可见,内部块也是,但内部块又是特殊的块:在外部块中存在的变量名,内部块可以重复使用,且可定义成其它的实体(entity)。这个变量从内部块出来后,又恢复成原始的实体。

    例如:

    //#include <iostream>
    using namespace std;
    
    int main () {
      int x = 1;
      int y = 3;
      {
        int x;   //ok,inner scope
    x = 100; //set value to inner x
    y = 50; //set value to outer y
    cout << "inner block: "; cout << "x: " << x << ' '; cout << "y: " << y << ' '; } cout << "outer block: ";
    cout << "x: " << x << ' '; cout << "y: " << y << ' '; return 0; }

    输出:
    inner block:

                                 x: 100

                                  y: 50

                                  outer block :

                                  x: 1

                                  y: 50



  • 相关阅读:
    JSP获取input(含正则表达式)
    Computability 7: Exercises
    Network 5: Data Link Layer
    PRML 7: The EM Algorithm
    PRML 6: SVD and PCA
    PRML 5: Kernel Methods
    PRML 4: Generative Models
    Computability 6: Reducibility
    Distributed Hash Table
    Network 4: Network Layer
  • 原文地址:https://www.cnblogs.com/guozqzzu/p/3586222.html
Copyright © 2011-2022 走看看