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


Please Help Members By Posting Answers For Below Questions

what is the structure pointer?

1648


Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10

15056


How can I direct output to the printer?

815


How can I get back to the interactive keyboard if stdin is redirected?

673


The % symbol has a special use in a printf statement. Explain how would you place this character as part of the output on the screen?

669






the maximum length of a character constant can be a) 1 character b) 8 characters c) 256 chaacters d) 125 characters

1806


What are data types in c language?

590


Explain the difference between #include "..." And #include <...> In c?

635


What does the file stdio.h contain?

608


difference between Low, Middle, High Level languages in c ?

1636


What is the maximum length of an identifier?

667


Is c still used?

606


what is uses of .net

1279


How arrays can be passed to a user defined function

581


Explain what are compound statements?

608