Wednesday, 27 June 2018

ch-11 Malloc and Calloc


Mcq
Difference between calloc() and malloc() is:
A) calloc() takes a single argument while malloc() needs two arguments
B) malloc() takes a single argument while calloc() needs two arguments
C) malloc() initializes the allocated memory to ZERO
 D) calloc() initializes the allocated memory to NULL

True false
1.  The function free() is used to release dynamically allocated memory back to the heap for possible reuse
2. The return type of malloc function is void.
3.  Linking is the process of putting together other program file and functions that are required by the program.
4  Size of the pointer variable depends on the data type that it points to.
5.  Linked list must require continuous memory allocation unlike array
6. malloc() allocates memory from the heap and not from the stack.
7. malloc() returns a float pointer if memory is allocated for storing float's and a double pointer if memory is allocated for storing double's.
8. Singly-linked lists contain nodes which have a data field as well as a next field, which points to the next node in the linked list.
9.  Binary search can be easily performed on a linked list.
10. The function free() is used to release dynamically allocated memory back to the heap for possible reuse.
11. malloc() is used to allocate memory run time.
Match the following
1.        
Malloc()
a)       
Malloc()
2.        
Calloc()
b)       
stropy
3.        
Header file required for stropy
c)        
Allocates and clear memory
4.        
Release memory
d)       
String.h
5.        
Link list is a dynamic data structure
e)       
Allocates memory but does not clear memory
6.        
Dynamic memory allocation
f)        
heap
7.        
Malloc()
g)       

8.        
Data structure used by malloc for object creation
h)       
Free()
9.        
Self referential data structure
i)         

10.    

j)         

11.    

k)       

12.    

l)         
Link list

Fill in the blanks
a)       
Linked List
b)       
Linked List
c)        
Free()
d)       
Void pointer
e)       
Calloc()
f)        
Void *
g)       
Linked List
h)       
getw()
i)         
Putw()
j)         
Alloc.h
k)       
Malloc returns
l)         
Area for dynamic memory
 m)
Self sequential structure
 n)
Sparse matrix
o)
heap
p)
dynamic


1.. if the memory is not allocated run time , malloc() returns _________.
2. ______________ is better to store data in application when frequent insertion and deletion operations are performed in application.
3. it is necessary to have a pointer to the next node in _________.
4. ______________data structure can grow or shrink in size during the excecution of a program .
5. the dynamic memory allocation function are_______ and malloc().
6. ____________ function is used to release the memory allotted in  dynamic memory allocation.
7. the header file which must be included , if you want to use malloc() or calloc() is______________
8. the function________ is used to read integer from a file.
9. the process of allocating memory at run time is known as _______________.
10. link list is a ____________ data  structure.
11. the data structure with most of the entities as 0(zero)is a(n).______________


Q/A
1Define the structure of a node of a singly linked list and use it to write a function to count the number of nodes in a singly linked list. The function should accept a pointer to the first node of the list and it should return the number of nodes in the list.
2. Given the linked list: Show how the linked list will appear after every operation (as mentioned below) is carried out. Assume that the operations are carried out one after another. addAtHead(5); addAtHead(4); addAfter(3, 7); // 7 is to be added after 3 delete(5);

3. 20 Write a program to create a link list. There should be 20 nodes in the list, each node contains an integer between 1-20. The list should be printed at the end.
4. What is the difference between array and linked list? Discuss the advantage of linked list over arrays.
5.  Write a program to create a link list. There should be 10 nodes in the list, each node contains an integer between 1 – 10. The list should be printed at the end.
6. define v) Dynamic memory allocation
7. What is dynamic memory allocation? Mention four functions used for dynamic memory manipulation.
8. 39 What is dynamic memory allocation? Mention four functions used for dynamic memory manipulation. b) What are command line arguments? Explain with the help of a suitable example.
42 Write a C program to construct a linear linked list in C to store student records. The record contains roll no. and total marks. The program stops when a negative roll no. is entered.












No comments:

Post a Comment

ch-12 File Handling

Mcq 1. What does fp point to in the program?   #include<stdio.h> int main() {   FILE *fp;   fp=fopen("trial",...