1.
Difference Between Static Memory
Allocation and Dynamic Memory Allocation
2.
Difference Between Malloc and Calloc
3.
Difference Between Global variable and
Local variable
4.
Difference Between Auto and Extern
5.
Difference Between Local variable and
static variable
1. Difference Between Static Memory
Allocation and Dynamic Memory Allocation
Static Memory Allocation
|
Dynamic Memory Allocation
|
Static Memory Allocation is performed at compile time.
|
Dynamic Memory Allocation is performed at run time.
|
It uses the concept of stack for allocating memory.
|
It uses the concept of heap for allocating memory.
|
Example :
int a [5];
|
Example :
int *ptr;
ptr=(int *)malloc(sizeof(int)*5);
|
2. Difference Between Malloc and Calloc
Malloc()
|
Calloc()
|
Malloc stands for memory
allocation.
|
Calloc stands for contiguous
memory allocation.
|
Malloc is faster than calloc.
|
Calloc is slower than malloc.
|
Malloc takes number of bytes as
an argument.
Void *malloc (size_in_bytes);
|
Calloc takes number of blocks and size
Void *calloc (number_of_blocks,
size_of_each_block_in_bytes);
|
The allocated region is
initialized to zero.
|
The contents of allocated memory contain unpredictable or garbage values.
|
3. Difference Between Global variable and Local variable
Global variable
|
Local variable
|
Global variable are declared outside all the functions.
|
Local variables are declared inside function.
|
Global variable can be accessed by all the function of
the program.
|
Local variable can be accessed only in the function in
which they are declared.
|
4. Difference Between Auto and Extern
Auto
|
Extern
|
It is used to declare variable as auto.
|
It is used to declare variable as extern.
|
The scope of the auto variable
|
The scope of the extern variable is global. It means it
can be accessed by all the function in a program.
|
If it is not initialized than it contains garbage value.
|
If it is not initialized than it contains zero value.
|
5. Difference Between Local variable and
Static variable
Local variable
|
Static variable
|
Local variable can be declared only inside function.
|
Static variable
|
If
|
It
|
It can be declared using auto Keyword.
|
It can be declared using static Keyword.
|
It is initialized each time a function is invoked.
|
It is initialized only once.
|
It lost its value upon exit from function.
|
It retains its value even after exit from function.
|
Post a Comment
Please do not enter any spam link in the comment box.