![]() ![]() To print the exact value, we need ‘float’ data type.įloat is 4 bytes, and we can print the value using %f. if we use int data type, it will strip off the decimal part and print only 97. For example, average marks can be 97.665. The floating point data type allows the user to type decimal values. ‘short int’ can be used to limit the size of the integer data type. If we add more digits to short int num1 = 10000, it will be out of range and will print wrong value. This is why it is safe to use %ld, unless you want the values to be always unsigned. Let us say the value of long notprime = -2300909090909933322 has a minus, but we print it as notprime is %lu, the correct value will not be printed. We can use %u in place of %d for unsigned int but even %d works. Though in practical situations, we may not use numbers that are this big, it is good to know the range and what data type we should use for programs with exponential calculations. ![]() Note that we have used ‘long long’ for sum, which is 8 bytes, whereas long is 4 bytes. We have used %hd for short, %d for int, and so on for printing each data type. Printf("num1 is % hd, number is % d, prime is % ld, notprime is % ld, sum is % lld", num1, number, prime, notprime, sum) How to print integer variables? Here is a small program that you can try and tweak to get different results and understand the range of short, int, and long. Integer types are further classified as – Data type Int values are always signed unless specifically mentioned. Integer types can be signed (with negative values) or unsigned values (only positive). We can use basic data types to store each of these data: char name Suppose we have to store student details like name, id, group, avg_marks, interest_on_fees. These are also termed as primary or fundamental data types. We will discuss these later in the article. Most of the time, for small programs, we use the basic fundamental data types in C – int, char, float, and double.įor more complex and huge amounts of data, we use derived types – array, structure, union, and pointer.Įnumeration and void consist of enum and void, respectively. That is why we have so many data types in C so that we can differentiate and segregate data in the best possible way. We can perform many operations (sum, average, concatenation, matching, etc.) if the data is stored in the correct format and with correct types. ![]() For example, the name is an array of characters, but age is better stored as an integer. Ramya Shankar | 02 Jan, 2023 Data Types in CĪpplications require different types of data to store information. ![]()
0 Comments
Leave a Reply. |