![]() The following example illustrates the float data types in C. The major advantage of floating point numbers over integers is that they can represent a much larger and wider range of digits as compared to int data type. Although the value of both the digits is the same, 8.0 has a decimal number which differentiates it with 8. Moreover, it should be noticed carefully that 8 is an integer but 8.0 is a floating-point number. The numbers that have a fractional part are called floating-point numbers. The float data type is used to store the floating-point numbers. This has proven when we added 1 in the num and printed it, we got 66 as output. Now, this variable is holding the ASCII value of character A. Then, we have initialized an int variable with ch. In the above example, we have initialized a variable ch with character A. Printf("Adding 1 to the character code \n") The following example illustrates the char data types in C. Since all characters and symbols can be represented in their numerical ASCII value, the char type is often considered as an int type. However, just like the integers the size of a char can vary according to the data type modifiers. The general size of a character is 1 byte. The ASCII code for upper case characters A to Z starts from 65 to 90 and for lower case characters a to z, it starts from 97 to 122. These codes are often called American Standard Code For Information Interchange or ASCII codes. The characters stored in a variable of char data type have a value equivalent to its integer code. The char data type is used to store the characters. And the final result is also being stored in another variable of the int data type. Here, we can easily observe that all the operations that are being conducted include the variables of the same data type ie., int data type. The above example declares and initializes an integer 5 and prints its multiples up to 5. The following example illustrates the int data types in C. However, if the operation of two integers results in a fraction number, the integer part will be stored as the final result. For example, 4/3 is fine but 4/3.0 is not fine. They can only be operated by/on integers themselves. In C language, the integers cannot be represented as floating or decimal point numbers. And that’s where we use data type modifiers, which we will be going to discuss later in this article. However, integers can be either negative or positive. Any number that falls in the range of -∞ to ∞ is said to be an integer. The int data type is used to store the integer values.
0 Comments
Leave a Reply. |