This repository contains a simple C program that demonstrates the use of basic data types and the printf
function to output values in C. The program stores a person's age, height, and grade, then prints these values to the console.
-
int
Integers from value a starting value of -2,147,483,648 and an ending value of 2,147,483,647 i.e. 4 bytes -
long
Long values range from -9,223,372,036,854,775,808 and goes up to 9,223,372,036,854,775,807. i.e. 8 bytes -
float
Decimal Values has a size of 4 bytes but has a precision in decimal digits upto 7 digits. -
double
Decimal Values has a size of 8 bytes but has a precision in decimal digits upto 15 digits. -
char
A single character with a size of 1 byte its value can range from 128 to 127 or 0 to 255. -
short
it can have values between -32768 and 32767 i.e. 2 bytes
Adding unsigned
infront of any data type can increase its range. Unsigned specifies the computer that the variable is positive only hence all the negative number space can be utilized for a more digits.
For eg:
short
has a range from -32768 to 32767. BUT
unsigned short
has a range from 0 to 65,535
unsigned
can be added to any data type to increase its size;
consts
are data types which cannot be changed unline variables. Where varaibles can be redefined to change there values consts cannot
const int age = 18;
Now the variable age cannot be changed into another variable.
-
int age = 21;
This line declares an integer variable namedage
and initializes it with the value21
. -
float height = 5.9;
This line declares a floating-point variable namedheight
and initializes it with the value5.9
. -
char grade = 'A';
This line declares a character variable namedgrade
and initializes it with the value'A'
. -
printf("Age: %d\n", age);
This line uses theprintf
function to print the value of theage
variable to the console. The %d format specifier is used for printing an integer. -
printf("Height: %.1f\n", height);
This line uses theprintf
function to print the value of theheight
variable to the console. The%.1f
format specifier is used for printing a floating-point number with one digit after the decimal point. -
printf("Grade: %c\n", grade);
This line uses the printf function to print the value of thegrade
variable to the console. The %c format specifier is used for printing a character.