we have to use realloc only after malloc or calloc ? or we
can use initially with out depending on whether we are
using malloc or calloc in our program ?
Answer Posted / vadivel t
Hi Vignesh,
Ur explanation about realloc() is correct. But the answer
is wrong. Because, it is possible to use realloc() before
using malloc() or calloc() function be used.
Lets, try the below code.
int *ptr;
ptr = (int *)realloc(NULL, 5);
printf("%d \n", ptr);
In this code, realloc will allocate five bytes of memory
and will return a valid pointer. It can be used in ur
program.
Conclusion:
It simple means that, if u pass a NULL pointer to a realloc
() function, it will exactly behave as like malloc().
| Is This Answer Correct ? | 6 Yes | 0 No |
Post New Answer View All Answers
What is structure and union in c?
What is scope rule of function in c?
Are pointers really faster than arrays?
what is the role you expect in software industry?
What is the difference between procedural and declarative language?
Difference between linking and loading?
What does p mean in physics?
What is a const pointer in c?
Is sizeof a keyword in c?
Is that possible to store 32768 in an int data type variable?
Can we use visual studio for c?
What is a structural principle?
What does d mean?
Is c is a high level language?
Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?