What is the use of Static local variable when we can get a global variable at the same cost?

前端 未结 6 646
迷失自我
迷失自我 2020-12-05 08:54

In C ,what is the use of static storage class when an external variable can serve its purpose at the same cost ie. both occupy storage space in the data segment of the execu

6条回答
  •  盖世英雄少女心
    2020-12-05 09:15

    A global variable is well, global, it can be accessed from anywhere.

    A static local variable has local scope. It is static, so it's lifetime runs across the lifetime of the application however it can only be accessed from the local scope (whether that scope is a function, a block, or a file)

提交回复
热议问题