Basic Data Types of C:
We have different types of data types in C:
Ø Types that store integers.
Ø Types that store non-integral numerical values.
Ø Types that store characters.
Examples of data types are:
1. int
2. double
3. char
4. float
5._Bool/Boolean
The difference between these data types is the type of memory the specific datatype allocates.
Depends upon the computer running. (machine-dependent) like which type of computer we use.
1. int:
Ø In this datatype we store integral value. (non-decimal number)
Ø It can also store minus sign values where the data indicate that it is negative.
Ø The int data type is a signed integer:
Which means that the number assigned may be positive, negative, or zero.
Ø If any value is taken zero or x the value taken must be hexadecimal (which means that the value taken must be below 16 numerical values).
Ø Example: int rgb = 0xGGHFDSA;
The values 190, -203, 0 are three valid examples.
Ø No embedded spaces are allowed between integers.
Ø The values larger than 999 cannot be expressed with commas for example 10,000 cannot be expressed with a comma but can be expressed as 10000.
2. float:
Ø In this datatype, we store number which contain floating-point numbers. (which can store decimal points).
Ø The value 3., 125.8, and -.0001 are all valid examples.
Ø Floating-point constants can also be expressed in scientific notation.
Ø 1.7e4 is a floating-point value expressed in this notation and represents the value 1.7*10 to the power 4.
3. double
Ø This datatype is like float but the only advantage in this is we can store large amount of data.
Ø All the float values are taken as double by the C compiler.
Ø All the float values are taken as double by the C compiler.
Ø To express any float constant in double then you can simply add f or F at the end.
Ø Example: 1.25f like it can store decimal values more than float can store.
4. _Bool/Boolean
Ø _Bool can also be called Boolean.
Ø In this datatype we can store values of 0 or 1.
Ø We can use _Bool for binary situations like on or off true or false.
Ø So, for example if we say that code has been executed by the compiler. In this situation we can use Boolean as it is a binary condition for which 0 indicates No and 1 indicates Yes.
Other data types
Ø The int satisfies most of the programmers in the beginning of C.
Ø But int also offers three adjective datatypes:
Ø Short, long, unsigned
Ø Short int is a type of variable which allows the large amount of memory to be stored into short forms.
Ø Long int can be used to store a large amount of numbers or data which is like double but double stores floating points whereas long int stores int values. Example: A number 12333333333333 can be written as 1.234e+7L.
Ø The type of datatype unsigned int is used to store only non-negative constants.
Ø unsigned int counter;
Ø it can also extend the accuracy of the data.