7. In a queue, the elements are always inserted at the rear end and deleted from the front end. Insert delete Front end Rear end 0 1 2 3 4 Pictorial representation of a Queue Queue 10 20 30
8.
9.
10.
11.
12.
13.
14.
15.
16.
17. Lucknow Hyderabad Ahmadabad Chennai Mumbai New Delhi Above graph shows the cities for which there is a direct flight.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37. malloc():Syntax ptr = (data_type*)malloc(size); ptr is a pointer variable of type data_type data_type can be any of the basic data type or user defined data type size is the number of bytes required
38.
39.
40. malloc():An Example void main() { char *str; str=(char *)malloc(10*sizeof(char)) if(str==NULL) { printf(“Out of memory”); exit(1); } strcpy( str,”Hello”); printf(“String is %s”,str); free(str); }
41.
42. calloc():Syntax ptr = (data_type*)calloc(n,size); ptr is a pointer variable of type data_type data_type can be any of the basic data type or user defined data type size is the number of bytes required ‘ n’ is the number of blocks to be allocated if size bytes
43. calloc():An Example void main() { char *str = NULL; str=(char *)calloc(10,sizeof(char)); if(str==NULL) { printf(“Out of memory”); exit(1); } strcpy( str,”Hello”); printf(“String is %s”,str); free(str); }
44.
45. realloc():Syntax ptr = (data_type*)realloc(ptr,size); The address of the newly allocated memory after reallocation data_type can be any of the basic data type or user defined data type size is the number of bytes required for reallocation Starting address of allocated memory obtained previously
46.
47. realloc():An Example void main() { char *str; str=(char *)malloc(10); strcpy( str,”Embedded”); printf(“Address of String %s is %d”,str,str); str=(char *)realloc(str,40); strcpy( str,”System Design”); printf(“Address of String %s is %d”,str,str); free(str); }