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
Why is sizeof () an operator and not a function?
Explain about the functions strcat() and strcmp()?
How can I read a binary data file properly?
What is a null pointer assignment error? What are bus errors, memory faults, and core dumps?
write a program in C that prompts the user for today's date,tomorrow's date and display the results.Use structures for today's date,tomorrow's date and an array to hold the days for each month of the year.
how to count no of words,characters,lines in a paragraph.
Write a program to print all permutations of a given string.
What are identifiers and keywords in c?
What is bubble sort in c?
Why we use conio h in c?
what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;
What is the best organizational structure?
What are enums in c?
What is the use of putchar function?
Describe the order of precedence with regards to operators in C.