0 votes
in C Plus Plus by

What is a Static Variable?

1 Answer

0 votes
by

A static variable is a local variable that retains its value across the function calls. Static variables are declared using the keyword “static”. Numeric variables which are static have the default value as zero.

The following function will print 1 2 3 if called thrice.

void f()

{

static int i;

++i;

printf(“%d “,i);

}

If a global variable is static, then its visibility is limited to the same source code.

Related questions

0 votes
asked Mar 10, 2020 in C Plus Plus by rahuljain1
0 votes
asked Mar 10, 2020 in C Plus Plus by rahuljain1
...