Static in C and C++

The static has two major role in C:

1. Define local static variable, which holds the value through the whole process of the execution. The static variable is stored in heap instead of stack.

2. Prohibit the access of the variable from other files. When a variable is static, it can not be extern.

The static has an extra usage in C++:

1. The static can decorate class variable and class function. When a member variable of a class or a member function of a class becomes static, it does not belong to any specific instance of the class. It will be shared among all the instance of the class, which can be called class function or class variable.

 

Advertisements
This entry was posted in C++. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s