Comparisons with short int in C - Printable Version +- QP School (https://qomplainerzschool.lima-city.de) +-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3) +--- Forum: C 18 Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=32) +--- Thread: Comparisons with short int in C (/showthread.php?tid=5151) |
Comparisons with short int in C - Qomplainerz - 07-26-2023 Description: Remember that the short int data type is useful when you need to save memory and the range of values is within its limitations. If you need a broader range or more precision, you may want to use a regular int or other data types like long int or long long int. Example: #include <stdio.h> int main() { short int a = 10; short int b = 20; if (a == b) { printf("a and b are equal.\n"); } else if (a < b) { printf("a is less than b.\n"); } else { printf("a is greater than b.\n"); } return 0; } Explanation: In this example, we compare two short int values a and b. The program checks whether a is equal to b, less than b, or greater than b, and prints the corresponding message. |