free alloc ptr

 #include <stdio.h>

#include<stdlib.h>


int main() {

    // Write C code here

    int n;

    printf("no of values you want to enter : ");

    scanf("%d", &n);

    float*ptr;

    float*ptr_free;

    ptr=(float*) calloc( n , sizeof(float));

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

        ptr_free=(float*)calloc(600, sizeof(float));

        printf("Enter value of element %d : ", i+1);//calloc will initilize all blocks = 0

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

        free(ptr_free);//free the memory allocated for other use

    }

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

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

    }

    free(ptr);//free the memory allocated for other use

    return 0;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings