MY mENU


Tuesday, 26 June 2012

What are the different storage classes in C?


C has three types of storage: automatic, static and allocated. Variable having block scope and without static specifier have automatic storage duration.
Variables with block scope, and with static specifier have static scope. Global variables (i.e, file scope) with or without the static specifier also have static scope.
Memory obtained from calls to malloc(), alloc() or realloc() belongs to allocated storage class.

Monday, 25 June 2012

What are the differences between malloc() and calloc()?


There are 2 differences.
First, is in the number of arguments. malloc() takes a single argument(memory required in bytes), while calloc() needs 2 arguments(number of variables to allocate memory, size in bytes of a single variable).


Secondly, malloc() does not initialize the memory allocated, while calloc() initializes the allocated memory to ZERO.

Saturday, 23 June 2012

Advantages of a macro over a function?


Macro gets to see the Compilation environment, so it can expand ___TIME__ __FILE__ #defines. 
It is expanded by the preprocessor. For example, you can’t do this without macros


#define PRINT(EXPR) printf( #EXPR “=%d\n”, EXPR) 


PRINT( 5+6*7 ) // expands into printf(”5+6*7=%d”, 5+6*7 );


You can define your mini language with macros:


#define strequal(A,B) (!strcmp(A,B))


Macros are a necessary evils of life. The purists don’t like them, butwithout it no real work gets done.