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 c so important?
What is malloc and calloc?
shorting algorithmS
What header files do I need in order to define the standard library functions I use?
hw can we delete an internal node of binary search tree the internal node has child node..plz write progarm
What is the purpose of the following code? Is there any problem with the code? void send(int count, short *to, short *from) { /* count > 0 assumed */ register n = (count + 7) / 8; switch (count % 8) { case 0: do { *to = *from++; case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; } while (--n > 0); } }
What is c programming structure?
State the difference between realloc and free.
what is the difference between north western polytechnique university and your applied colleges?? please give ur answers for this. :)
Explain what is the benefit of using #define to declare a constant?
Write a code to generate a series where the next element is the sum of last k terms.
Define Array of pointers.
What happens if a header file is included twice?
What is pass by reference in functions?
the 'sizeof' operator reported a larger size than the calculated size for a structure type. What could be the reason?