int memory alloc (array)

 #include <stdio.h>

#include<stdlib.h>


int main() {

    // Write C code here

    int*ptr;

   // ptr = malloc( 6 * 4);//memory alloc

   

    //printf("The size of int is %d\n" , sizeof(int));//will give memory size of int 

    //printf("The size of int is %d\n" , sizeof(char));

    //printf("The size of int is %d\n" , sizeof(float));

    //printf("The size of int is %d\n" , sizeof(long));

    ptr = (int*)malloc( 6 * sizeof(int));

    for(int i = 0 ; i< 6 ; i++){

        printf("enter %d element ", i);

        scanf("%d",&ptr[i]);

    }

    for(int i = 0 ; i< 6 ; i++){

        printf("%d\n",ptr[i]);

    }

    return 0;

}


//***************float*******


#include <stdio.h>

#include<stdlib.h>


int main() {

    // Write C code here

    float*ptr;

    ptr=(float*) malloc( 6 * sizeof(float));

    for (int i = 0 ; i<6;i++){

        printf("Enter value of element %d : ", i+1);

        scanf("%f",&ptr[i]);

    }

    for (int i = 0 ; i<6;i++){

    printf("%0.3f\n",ptr[i]);

    }

    return 0;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings