C strengthening Summer workshop notes 1

  • Debugging using Eclipse

  • Variable Scope:

    • Globle Scope

      1. Outside any function

      2. Can be used by lator blocks of code:

    • int g;                                                                                          int main(void){                                                                                        g=0;}

       3. Only one instance if any name can exist at the same level     

  • int a;                                                                                        int a;//is illegal
  • Scope inside blocks

    1. blocks inherit all variables from global scope

    2. May declare variables with the same name to hide(but not replace)global varibles.(if blocks are nested, variables declared in an inner block may hide variables declared in an outer block)

    3. Variables declared inside a block have a different scope from global variables, and may even be of a different type:

  • int a;
    void f(void)
    {
        float a;/* different from global `a' */
        float b;
        a = 0.0;/* sets `a' declared in this block to 0.0 */
                /* global `a' is untouched */
        {
            int a;/* new `a' variable */
            a = 2;/* outer `a' is still set to 0.0 */
        }
        b = a;/* sets `b' to 0.0 */
    }
    /* global `a' is untouched by anything done in f() */

    4. This method of hiding variables is a potential source of bugs and some compilers will issue a warning if a variable is found to be hidden.

    5. We usually group all the local variables in the same scope.

    6. Unlike java, the scoping of a function itself is always global.


转载于:https://my.oschina.net/smartman/blog/268170

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值