Write a program to dynamically allocate memory to integer, float, and character type
of data. Initialise the value of float during the compile time, and the value of integer
and character must be entered during the execution time.
Answers
Answer:
I am writing the program in C language.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int *i;
char *c;
float *f;
i=(int*)malloc(1*sizeof(int)); /*Dynamically allocating Memory*/
c=(char*)malloc(1*sizeof(char)); /*Dynamically allocating Memory*/
f=(float*)malloc(1*sizeof(float)); /*Dynamically allocating Memory*/
*f = 95.7256; /*Initializing value of float*/
printf("Enter an integer value: ");
scanf("%d",i); /*Value of integer to be entered at execution time*/
printf("Enter a character value: ");
scanf(" %c",c); /*Value of character to be entered at execution time*/
printf("Values entered are : %d, %c, %.2f",*i,*c,*f);
/*Allocated memory made free*/
free(i);
free(c);
free(f);
return 0;
}
Sentences written between /* ... */ are comments which don't affect the program in any way . Comments are given for better understanding of program.
Python program to dynamically allocate memory to integer, float, and character type of data.
Language used : Python Programming
Program :
x=int(input("Enter an integer : "))
y=0.987
z=input("Enter a character : ")[0]
print("Integer value is : ",x, " Float value is : ", y," Character value is : ",z)
Input :
Enter an integer : 345
Enter a character : g
Output :
Integer value is : 345 Float value is : 0.987 Character value is : g
Learn more :
- Advantages of Programming in python
brainly.in/question/11007952
- Indentation is must in python. Know more about it at :
brainly.in/question/17731168