Posts

Showing posts from June, 2023

USE OF MALLOC() AND REALLOC() AND FREE(ptr) in c

  #include <stdio.h> #include <stdlib.h> int main () { //     // use of malloc //     int *ptr, n; //     printf("Enetr the sie of the array you want to create\n"); //     scanf("%d", &n); //     ptr = (int *)malloc(n * sizeof(int)); //     for (int i = 0; i < n; i++) //     { //         printf("Enter the value of no %d of this array\n",i); //         scanf("%d", &ptr[i]); //     } //      for (int i = 0; i < n; i++) //     { //         printf("The value at %d of this array is %d\n",i,ptr[i]);         //    } // use of calloc     int * ptr , n ;     printf ( "Enetr the sie of the array you want to create \n " );     scanf ( " %d " , & n );     ptr = ( int *) calloc ( n , sizeof ( int ));     for ( int i...

USE OF MALLOC() IN C

  #include <stdio.h> #include <stdlib.h> int main () { //     // use of malloc     int * ptr , n ;     printf ( "Enetr the sie of the array you want to create \n " );     scanf ( " %d " , & n );     ptr = ( int *) malloc ( n * sizeof ( int ));     for ( int i = 0 ; i < n ; i ++)     {         printf ( "Enter the value of no %d of this array \n " , i );         scanf ( " %d " , & ptr [ i ]);     }       for ( int i = 0 ; i < n ; i ++)     {         printf ( "The value at %d of this array is %d \n " , i , ptr [ i ]);            }   free ( ptr );             return 0 ; } OUTPUT: Enetr the sie of the array you want to create 5 Enter the value of no 0 of this array 78 Enter the value of no 1 of this array 56 Ente...