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
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 |
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 |
How many keywords (reserve words) are in c?
Should a function contain a return statement if it does not return a value?
A collection of data with a given structure for excepting storing and providing on demand data for multiple users a) linked list b) datastructer c) database d) preprocessor
#include show(int t,va_list ptr1) { int a,x,i; a=va_arg(ptr1,int) printf(" %d",a) } display(char) { int x; listptr; va_star(otr,s); n=va_arg(ptr,int); show(x,ptr); } main() { display("hello",4,12,13,14,44); }
program for comparing 2 strings without strcmp()
Can anyone help me with this please? Need to print the below values.. Thanks 1 1 2 1 2 3 1 2 3 4
What is the use of in c?
Is it cc or c in a letter?
Describe the difference between = and == symbols in c programming?
Write a program to print "hello world" without using a semicolon?
Write a program to print the following series 2 5 11 17 23 31 41 47 59 ...
#include<stdio.h> void main() { int a [5]; for (i=0; i<=4; i++) printf(ā%dā ,a[i]); }