STATIC static variable a little experience

xiaoxiao2021-03-05  23

STATIC static variable a little experience

#include using namespace std;

INT FAC (INT N);

INT main () {int m = 0, a, b, c; cout << "INPUT A, B, C:"; CIN >> A >> B >> C; M = Fac (a) FAC (B ) FAC (C); cout << "m =" << m << endl; return 0;}

INT FAC (INT N) {static int f = 1; // int F = 1; // You can know the role of Static variables! f = f * n; return f;}

In the sub function:

1. Static variables will only be initialized once, and then the subunies each time the subunies are only operated.

2. Ordinary (partial) variables are reinitialized when the subunies are called each time.

The difference between them says that it can be considered: In the subunsence, the static variable only occupies a distinct memory address; and local variables take up a new memory address each time, this address may be random.

转载请注明原文地址:https://www.9cbs.com/read-37701.html

New Post(0)