#include<stdio.h>
#include<conio.h>
int main()
{
int age=22;
float height=5.4;
char sex='M';
printf("Age: %d \nHeight: %f \nSex: %c",age,height,sex);
getch();
}
/*In the above program ,int,height and char variables are declared and valu are assigned.Using printf()
statement values are displayed.
Maximum length of a variable up to 31 characters
The variable should not be a c keyword
The variable name should not start with a digit*/
The above code is a C program that declares and assigns values to three variables: an integer variable age
, a floating-point variable height
, and a character variable sex
.
- The program starts by including the standard input/output header file
stdio.h
and the non-standard conio.h header file which provides thegetch()
function. - Inside the
main()
function, it declares three variablesage
,height
,sex
with the int, float, char data types respectively and assigns values to them. - The program uses the
printf()
function to print the values of the variablesage
,height
andsex
using format specifiers%d
,%f
and%c
respectively. - The
getch()
function is used to wait for the user to press a key before terminating the program.
The program also includes comments explaining the code and some rules for naming a variable in C language.
It’s important to note that the getch()
function is not a part of the standard C library, it is provided by the non-standard conio.h header file and it’s use is not recommended in most cases.
Thanks
Write a program to declare and initialize variables and display them.