WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c
file management?
Answer Posted / tinku
There are two differences.
First, is in the number of arguments.
Malloc() takes a single argument (memory required in bytes),
Calloc() needs two arguments.
Secondly, malloc() does not initialize the memory allocated, while
calloc() initializes the allocated memory to ZERO.
calloc() allocates a memory area, the length will be the product of its parameters. calloc fills the memory with ZERO's and returns a pointer to first byte. If it fails to locate enough space it returns a NULL pointer.
Syntax: ptr_var=(cast_type *)calloc(no_of_blocks , size_of_each_block);
i.e. ptr_var=(type *)calloc(n,s);
malloc() allocates a single block of memory of REQUSTED SIZE and returns a pointer to first byte. If it fails to locate requsted amount of memory it returns a null pointer.
Syntax: ptr_var=(cast_type *)malloc(Size_in_bytes);
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
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.
how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software
write a program for the normal snake games find in most of the mobiles.
which of the following statement is wrong a) mes=123.56; b) con='T'*'A'; c) this='T'*20; d) 3+a=b;
What is #define?
c program to compute AREA under integral
Why do some versions of toupper act strangely if given an upper-case letter?
What are pointers? Why are they used?
How can I manipulate individual bits?
count = 0; for (i = 1;i < = 10; i++);count = count + i; Value of count after execution of the above statements will be a) 0 b) 11 c) 55 d) array
What is "Hungarian Notation"?
Why is python slower than c?
Write a program to generate a pulse width frequency of your choise,which can be variable by using the digital port of your processor
Is fortran still used in 2018?
Do you know what are bitwise shift operators in c programming?