how to know a type of a numbe in c
Checking the Type of a Number in C
To check the type of a number in C, you can use the sizeof
operator and the printf
function to display the size of the variable in bytes. Here are the steps:
Declare the Variable: Declare a variable of the type you want to check.
Use the sizeof Operator: Use the
sizeof
operator to determine the size of the variable in bytes.Display the Size: Use the
printf
function to display the size of the variable.
Here's an example of how you can do this:
#include <stdio.h>
int main() {
int num;
float decimalNum;
printf("Size of int: %d bytes\n", sizeof(num));
printf("Size of float: %d bytes\n", sizeof(decimalNum));
return 0;
}
In this example, the sizeof
operator is used to determine the size of the int
and float
variables, and the printf
function is used to display the size in bytes.