Answer Posted / vadivel t
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 |
Post New Answer View All Answers
Explain how can you determine the size of an allocated portion of memory?
what is ur strangth & weekness
Why is structure padding done in c?
Is it possible to have a function as a parameter in another function?
differentiate built-in functions and user – defined functions.
What is hash table in c?
What does & mean in scanf?
Explain what is the advantage of a random access file?
we need to calculating INCOME TAX for the person. The INCOME TAX is as follows:- First $10000/- of income : 4% tax Next $10000/- of income : 8% tax Next $10000/- of income : 11.5% tax above $10, 00,00/- : 15% tax What is the Solution of this Question ?
Given below are three different ways to print the character for ASCII code 88. Which is the correct way1) char c = 88; cout << c << " ";2) cout.put(88);3) cout << char(88) << " "; a) 1 b) 2 c) 3 d) constant
The OS is a program that uses various data structures. Like
all programs in execution, you can determine the
performance and other behavior of the OS by inspecting its
state - the values stored in its data structures. In this
part of the assignment, we study some aspects of the
organization and behavior of a Linux system by observing
values of kernel data structures exposed through the /proc
virtual file system.
The /proc virtual file system:
Linux uses the /proc file system to collect information
from kernel data structures. The /proc implementation
provided with Linux can read many different kernel data
structures. If you cd to /proc on a Linux machine, you will
see a number of files and directories at that location.
Files in this directory subtree each corresponds to some
kernel data structure. The subdirectories with numeric
names contain virtual files with information about the
process whose process ID is the same as the directory name.
Files in /proc can be read like ordinary ASCII files. You
can open each file and read it using library routines such
as fgets() or fscanf(). The proc (5) manual page explains
the virtual files and their content available through
the /proc file system.
Requirements in detail:
In this part, you are asked to write a program to report
the behavior of the Linux kernel. Your program should run
in two different versions. The default version should print
the following values on stdout:
• Processor type
• Kernel version
• The amount of memory configured into this computer
• Amount of time since the system was last booted
A second version of the program should run continuously and
print lists of the following dynamic values (each value in
the lists is the average over a specified interval):
• The percentage of time the processor(s) spend in
user mode, system mode, and the percentage of time the
processor(s) are idle
• The amount and percentage of available (or free)
memory
• The rate (number of sectors per second) of disk
read/write in the system
• The rate (number per second) of context switches in
the kernel
• The rate (number per second) of process creations
in the system
If your program (compiled executable) is called proc_parse,
running it without any parameter should print out
information required for the first version. Running it with
two parameters "proc_parse
What is the difference between the expression “++a” and “a++”?
What is the meaning of c in c language?
Write a program to swap two numbers without using third variable?
What is function in c with example?