Q:

C program to create memory for int, char and float variable at run time.

-1

C program to create memory for int, char and float variable at run time.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

/*C program to create memory for int, 
char and float variable at run time.*/
 
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int *iVar;
    char *cVar;
    float *fVar;
     
    /*allocating memory dynamically*/
     
    iVar=(int*)malloc(1*sizeof(int));
    cVar=(char*)malloc(1*sizeof(char));
    fVar=(float*)malloc(1*sizeof(float));
     
    printf("Enter integer value: ");
    scanf("%d",iVar);
     
    printf("Enter character value: ");
    scanf(" %c",cVar);
     
    printf("Enter float value: ");
    scanf("%f",fVar);
     
    printf("Inputted value are: %d, %c, %.2f\n",*iVar,*cVar,*fVar);
     
    /*free allocated memory*/
    free(iVar);
    free(cVar);
    free(fVar);
 
    return 0;
}
    Enter integer value: 100
    Enter character value: x
    Enter float value: 123.45
    Inputted value are: 100, x, 123.45

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

<< C program to input and print text using Dynamic Me...