#include<stdio.h>
#include<conio.h>
int main()
{
int r=2;
float area=3.14*r*r;
printf("Area=%f",area); //use %f or %g//
getch();
}
/*The expression is solved at a run time and assigned to area at a run time.Hence,it is called
dynamic initialization*/
The above program demonstrates dynamic initialization, which means the initialization of a variable with a value that is determined at runtime. In this program, the variable “r” is initialized with the value 2, and the variable “area” is initialized with the value of the expression “3.14rr”, which calculates the area of a circle with a radius of 2.
The “printf” statement is then used to print the value of the “area” variable, which is the result of the calculation performed during initialization. The format specifier “%f” is used to print the value of a float or double variable, and the argument passed to the function is the “area” variable.
The “getch()” function is used to hold the console window open so that the output can be read by the user before the program exits.
In summary, this program demonstrates how to perform dynamic initialization of a variable, perform a calculation at runtime and assign the result to a variable, and display the value of a variable using the printf() function.
Thanks