C++ Storage Duration, Scope, and Linkage

Storage Duration, Scope, and Linkage


C++ uses three separate schemes for storing data, and the schemes differ in how long they preserve data in memory.

1. Variables declared inside a function definition have automatic storage duration; that includes function parameters. They are created when program execution enters the function or block in which they are defined, and the memory used for them is freed when execution leaves the function or block. C++ has two kinds of automatic storage duration variables.

2.Variables defined outside of a function definition or else by using the keyword static have static storage duration. They persist for the entire time a program is running. C++ has three kinds of static storage duration variables.

3.Memory allocated by the new operator persists until freed with the delete operator or until the program ends, whichever comes first. This memory has dynamic storage duration and sometimes is termed the free store.

你可能感兴趣的:(C++,c,C#)