How much memory does a static variable takes?

How much memory does a static variable takes?

Memory allocated to static variable is not depends on static keyword. only depends on data type.So, it is called an static specifier.It only occupies the values of int,char,float etc.static keyword does not required any memory.
example:

static int p;
static char q;
static float r;
static short int s;
printf(" %d %d %d %d ", sizeof(p), sizeof(q),  sizeof(r), sizeof(s));

o/p: 4 1 4 2 (In case of 32 bit compiler)

In case of Dos static occupies 2 bytes for integer.

By:Vivek Kr. Agarwal
Date:2003-01-09 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related C Subjective Links

C Subjective interview questions and answers for experienced and fresher