unit 4 qp
unit 4 qp
CS3251_PIC
4931_Grace College of Engineering,Thoothukudi
CS3251_PIC
4931_Grace College of Engineering,Thoothukudi
CS3251_PIC
4931_Grace College of Engineering,Thoothukudi
17. Define dynamic memory allocation functions and list its types.
The process of allocating memory during program execution is called dynamic memory
allocation.
C language offers 4 dynamic memory allocation functions. They are,
1. malloc()
2. calloc()
3. realloc()
4. free()
18. Explain malloc with its syntax.
malloc () function is used to allocate space in memory during the execution of the
program.
malloc () does not initialize the memory allocated during execution. It carries
garbage value.
malloc () function returns null pointer if it able to allocate requested amount
of memory.
Syntax
malloc (number *sizeof(int));
19. Explain calloc with its syntax.
It allocates multiple blocks of requested memory. calloc () initializes the allocated
memory to zero
Calloc () function is also like malloc () function. But calloc () initializes the allocated
memory to zero. But, malloc()
Syntax
calloc (number, sizeof(int));
20. Explain realloc with its syntax.
realloc () function modifies the allocated memory size by malloc () and calloc ()
functions to new size.
allocated for the full size of reallocation, then copies the existing data to new block
and then frees the old block.
Syntax
realloc (pointer_name, number * sizeof(int));
21. Explain free function with example.
free () function frees the allocated memory by malloc (), calloc (), realloc () functions and
returns the memory to the system.
Syntax: free (pointer_name);
22. What is the output of the following code fragment? (May 19)
struct point
{ int x;
int y;
}; struct point origin, *pp;
main()
{
pp=& origin;
printf("origin is (%d%d)\n",(*pp).x,pp->y);
} Output: origin is (00)
UNIT-IV / PART-B
1. What is a structure? Create a structure with data members of various types and declare
two structure variables. Write a program to read data into these and print the same.
Write short notes on structure Declaration. (Jan 16)
CS3251_PIC
4931_Grace College of Engineering,Thoothukudi
2. Write a program to print student grade using structure / Write a C program to create a
mark sheet for students using structure. (Jan 14)
3. (i) Write short notes on nested structure / Explain the concept of structure within
structure with suitable program.
(ii) Define and declare a structure to store date, which including day, month and year.
(Jan 14)
4. Define a structure called book with book name, author name and price. Write a C
program to read the details of book name, author name and price of 200 books in a
library and display the total cost of the books and book details whose price is above
Rs.500. (May 15)
5. Write a C program to store the employee information using structure and search
a particular employee using employee number? (Jan 14) (May 14)
6. Explain dynamic memory allocation in detail (or) What is dynamic memory allocation?
Explain various C functions that are used for the same with examples. (May 19)
7. i) Difference between static memory allocation and dynamic memory allocation in c.
ii) Difference between malloc( ) and calloc( ) functions in c.
8. Write a C program to implement singly linked list using dynamic memory allocation.
9. Define structure in C. Also specify the pointer and structure with example. (May 18)
10. i) Write a C program for accessing structure member through pointer using dynamic
memory allocation. (May 18)
ii) Write a short note on singly linked list and specify how the nodes are created in
singly linked list. (May 18)
11. What are self -referential structures? Explain with suitable examples. (May 19)
CS3251_PIC