Monday, 14 May 2012

difference between Scope and Lifetime?

Scope: It defines the visibility/accessibility of the variable in a program. For example take a local variable where the scope is local to that function.For static global variable,scope is limited to that file only. For global variable the scope is across multiple files (if it is with extern specifier)
Lifetime: It is the duration of time for which the variable holds the value during the execution of a program. For local variable the lifetime is within the functional block in which it is declared. The memory allocated when function starts and deallocated when it terminates. So,the lifetime of the variable defined in that block is local the functional block.
On the other side, for static variable, the life time will be the entire execution of the program. When the variable is used it takes the last stored value in that memory location. The value persists even between function calls. The life time is entire execution of the program.

1 comment:

  1. Bet of the Day (2021) - Dr.D.C.
    We want to help you learn how to 속초 출장마사지 become a casino bet. We've 논산 출장안마 got some big names in the 제주 출장안마 gambling business in the United 제천 출장안마 States that we are 세종특별자치 출장샵 glad to share with you.

    ReplyDelete