#include<stdio.h>
#include<conio.h>
int main()
{
int Num=12;
int WEIGHT=25;
float HeIgHt=4.5;
char name[10]="NESARK"; //not more then ten
printf("Num: %d \nWeight: %d \nHeight: %g \nName: %s",Num,WEIGHT,HeIgHt,name);
getch();
}
/*The variable name may be a combination of uppercase and lowercase characters,
For int use %d or %i,
For float use %f or %g, */
The above code is a C program that declares and assigns values to four variables: an integer variable Num
, an integer variable WEIGHT
, a floating-point variable HeIgHt
and a character array name
.
- 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 four variablesNum
,WEIGHT
,HeIgHt
andname
with the int, int, float and char array data types respectively and assigns values to them. - The program uses the
printf()
function to print the values of the variablesNum
,WEIGHT
,HeIgHt
andname
using format specifiers%d
,%d
,%g
and%s
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.
Also, you are right that variable names in C can be a combination of uppercase and lowercase characters. And also, it’s good to use format specifiers which are specific to the data types, like %d
for int, %g
for float and %s
for char array.
Thanks