what is calloc and malloc?
Answers were Sorted based on User's Feedback
Hi Jhothi16,
how do u say calloc is for reallocation???..
Ans is,
Both are serving for the purpose of dynamic memory
allocation.
But malloc and calloc differs in two ways.
1.After allocating memory using malloc(), the data elements
in the memory will not be initialised. Means, it contains
garbage values.
But calloc() initialise all the data elements to 0.
2.malloc() allocates memory in terms of bytes.it accepts
only one argument, which says no of bytes to be allocated.
But calloc() allocates memory interms of blocks. it is
widely used when there is a need to allocated memory for an
array.
it accepts two arguments, 1st says, no of blocks to be
allocated and next argument says the size of the block.
ex:
calloc(10, sizeof(int))
-> it allocates 40 bytes, if the compiler allocates 4 bytes
for an int variable.
| Is This Answer Correct ? | 17 Yes | 1 No |
Answer / jothi16
calloc means reallocate the memory.malloc used to allocate
the memory
| Is This Answer Correct ? | 6 Yes | 20 No |
int i=3; this declaration tells the C compiler to a) reserve space in memory to hold the integer value b) associate the name i with this memory location c) store the value 3 at this location d) all the above
Write code for initializing one dimentional and two dimentional array in a C Program?
5 Answers Deshaw, Edutech, GMD,
what wud be the output? main() { char *str[]={ "MANISH" "KUMAR" "CHOUDHARY" }; printf("\nstring1=%s",str[0]); printf("\nstring2=%s",str[1]); printf("\nstring3=%s",str[2]); a)string1=Manish string2=Kumar string3=Choudhary b)string1=Manish string2=Manish string3=Manish c)string1=Manish Kumar Choudhary string2=(null) string3=(null) d)Compiler error
Write a program to find whether the given number is prime or not?
How do you use a 'Local Block'?
Which is not valid in C a) class aClass{public:int x;}; b) /* A comment */ c) char x=12;
write a program that reads lines(using getline), converts each line to an integer using atoi, and computes the average of all the numbers read. also compute the standard deviation.
write a function that accepts an integer/char array and an search item.If the search item is there in the array return position of array and value else return -1.without using other array,without sorting,not to use more than one loop?
Is exit(status) truly equivalent to returning the same status from main?
write a programme to enter some number and find which number is maximum and which number is minimum from enterd numbers.
What is actual argument?
print the pattern 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 if n=5