Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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 ?

Answers were Sorted based on User's Feedback



we have to use realloc only after malloc or calloc ? or we can use initially with out depending on..

Answer / 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

we have to use realloc only after malloc or calloc ? or we can use initially with out depending on..

Answer / vignesh1988i

ya we must use realloc (RE-ALLOCATION) only after malloc (MEMORY ALLOCATION) ....
actually realloc is a fuction which will be mainly implemented after knowing the accurate amount of memory that is going to be used... if our memory is allocated using malloc is less compared to the total values that is going to be stored we will RE-ALLOCATE the memory to our wish to store all the values...

but in other case if the data has been stored in the allocated block by malloc , but still more is remaining we can again RE-ALLOCATE usin realloc funcion.......


thank u

Is This Answer Correct ?    3 Yes 2 No

Post New Answer

More C Interview Questions

1.write a program to merge the arrays 2.write efficient code for extracting unique elements from a sorted list of array?

3 Answers   Qualcomm,


Write a C program to accept a matrix of any size. Find the frequency count of each element in the matrix and positions in which they appear in the matrix

0 Answers   CLG,


HOW CAN ADD OUR FUNCTION IN LIBRARY.

5 Answers  


In c programming, explain how do you insert quote characters (? And ?) Into the output screen?

0 Answers  


What is the value of uninitialized variable in c?

0 Answers  


Tell me with an example the self-referential structure?

0 Answers  


True or false: If you continuously increment a variable, it will become negative? 1) True 2) False 3) It depends on the variable type

7 Answers  


Explain continue keyword in c

0 Answers  


What is type qualifiers?

0 Answers  


why integer range between -327680to+32767

2 Answers  


ABCDCBA ABC CBA AB BA A A

4 Answers   TCS,


What functions are used for dynamic memory allocation in c language?

0 Answers  


Categories