Discuss different data types used in C with example.



1) int
2) float
3) double
4) char

int: These are whole numbers, both positive and negative. Unsigned integers (positive values only) are supported. In addition, there are short and long integers. Its data range is -32768 to +32767
The keyword used to define integers is: int.
An example of an integer value is 32. An example of declaring an integer variable called sum is:
            int sum;
            sum = 20;

float: These are numbers which contain fractional parts, both positive and negative. The keyword used to define float variables is: float. Its data range is -3.4e38 to +3.4e38.
An example of a float value is 34.12. An example of declaring a float variable called money is:
            float money;
            money = 0.12;
double:double is used to define BIG floating point numbers. It reserves twice the storage for the number. Its data range is -1.7e38 to +1.7e38. An example:
        double Atoms;
        Atoms = 2500000;
   
Char: These are single characters. The keyword used to define character variables is: char
An example of a character value is the letter A. An example of declaring a character variable called letter is:
char letter;
            letter = 'A';
Next Post Previous Post
No Comment
Add Comment
comment url