Why does commenting out an initialized global variable loses 4 bytes of data from data segment whereas commenting out an uninitialized global variable loses 8 bytes of data from BSS segment?
PROGRAM1:
#include <stdio.h>
int global1 = 20; /* initialized global variable stored in DS*/
int global2; /* Uninitialized global variables stored in BSS segment*/
int global3=0; /* Global variables initialized to zero are stored in BSS*/
int main(void)
{
static int i = 100; /* Initialized static variable stored in DS*/
static int j=0; /* Static variables initialized to 0 are stored in bss*/
//int l=100; /* stack stores the auto variables*/
int k; /* stack stores the auto variables*/
return 0;
}
Data:504 BSS 32
PROGRAM2:
#include <stdio.h>
//int global1 = 20; /* initialized global variable stored in DS*/
int global2; /* Uninitialized global variables stored in BSS segment*/
int global3=0; /* Global variables initialized to zero are stored in BSS segment*/
int main(void)
{
static int i = 100; /* Initialized static variable stored in DS*/
static int j=0; /* Static variables initialized to 0 are stored in BSS segment*/
//int l=100; /* stack stores the auto variables*/
int k; /* stack stores the auto variables*/
return 0;
}
Data :500, BSS 32
PROGRAM3:
#include <stdio.h>
//int global1 = 20; /* initialized global variable stored in DS*/
//int global2; /* Uninitialized global variables stored in BSS segment*/
int global3=0; /* Global variables initialized to zero are stored in BSS segment*/
int main(void)
{
static int i = 100; /* Initialized static variable stored in DS*/
static int j=0; /* Static variables initialized to 0 are stored in BSS segment*/
//int l=100; /* stack stores the auto variables*/
int k; /* stack stores the auto variables*/
return 0;
}
Data 500, BSS 24 (why 24 and why not 28?)