Sunday, 27 July 2014

SIZEOF different data types: (int,float,double,char) vs SIZEOF a pointer & pointer datatype

size of data types (int,float,double,char) is compiler dependent which vary depending on the compiler.

sizeof a pointer is kernel dependent .

data type of pointer : void or (char *)0


Saturday, 26 July 2014

declaration & initialisation of a global & local variable. (linux)

global variable:

In C global variables are stored in data segment ,
if variable is only declared & not initialised with some value :  that variable is stored in BSS(block startup symbol) segment which is starting address of data segment where it is initialised with value '0' with a logical address.When we assign some value to it then it will move to main data segment .
if variable is assigned value at time of declaration : it directly moves to main data segment with some physical addressing.

local variables:

Local variables are stored in stack segment of process context
if variable is only declared & not initialised with some value: logical address is given to the variable like if we initialise "int val" then only 4 bytes or 8bytes (depending on compiler) with starting logical address is given to the variable.But physical addressing is provided by kernel at the time we assign some value to variable.



Saturday, 5 July 2014

sizeof a pointer

size of pointer in linux vary with kernel version
for old kernels its: 4bytes
for new versions above 3 .10 : 8bytes

sizeof vs strlen
sizeof-prints even null character
strlen-prints size excluding null 

printf("hello %s\n",sizeof(char ));

output:
run time error :segmntation fault

printf("hello %c\n",sizeof(char ));
out:
hello

no warning or error