Ans: The typedef help in easier modification when the programs are ported to another machine.
A descriptive new name given to the existing data type may be easier to understand the code.
Blog Author: Vijay Kumar
What is the difference between "calloc(...)" and
|
1. calloc(...) allocates a block of memory for an array of elements of a
|
certain size. By default the block is initialized to 0. The total number of
|
memory allocated will be (number_of_elements * size).
|
malloc(...) takes in only a single argument which is the memory
|
required in bytes. malloc(...) allocated bytes of memory and not blocks
|
of memory like calloc(...).
|
2. malloc(...) allocates memory blocks and returns a void pointer to the
|
allocated space, or NULL if there is insufficient memory available.
|
calloc(...) allocates an array in memory with elements initialized to 0
|
and returns a pointer to the allocated space. calloc(...) calls malloc(...)
|
in order to use the C++ _set_new_mode function to set the new
|
handler mode.
Blog Author: Vijay Kumar
|
Structure | Union |
---|---|
i. Access Members | |
We can access all the members of structure at anytime. | Only one member of union can be accessed at anytime. |
ii. Memory Allocation | |
Memory is allocated for all variables. | Allocates memory for variable which variable require more memory. |
iii. Initialization | |
All members of structure can be initialized | Only the first member of a union can be initialized. |
iv. Keyword | |
'struct' keyword is used to declare structure. | 'union' keyword is used to declare union. |
v. Syntax | |
struct struct_name
{
structure element 1;
structure element 2;
----------
----------
structure element n;
}struct_var_nm;
| union union_name
{
union element 1;
union element 2;
----------
----------
union element n;
}union_var_nm;
|
vi. Example | |
struct item_mst
{
int rno;
char nm[50];
}it;
| union item_mst
{
int rno;
char nm[50];
}it;
|