0
2.8kviews
What do you mean by register and static storage class? Explain with example.
1 Answer
0
119views

1) The register storage class is used to define local variables that should be stored in a register instead of RAM.

{
registerint  miles;
}

The variable miles will now be stored in register memory. Hence, it can be used again when the program is run next time.

2) The static Storage Class

The static storage class instructs the compiler to keep a local variable in existence during the life-time of the program instead of creating and destroying it each time it comes into and goes out of scope.

In C programming, when static is used on a data member, it causes only one copy of that member to be shared by all the objects of its class.

Example:

static int i=5;
void func()
 printf (“%d”,i);
void main()
{
  i++;
  printf(“%d \n”, i);
  func();
}

Output

6

5

The second output is still 5 because the operations in main() did not affect the value of ‘i’ in func() as it was declared static.

Please log in to add an answer.