Type casting 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: Type casting with short int in C (/showthread.php?tid=5150) |
Type casting with short int in C - Qomplainerz - 07-26-2023 Example: #include <stdio.h> int main() { int num1 = 200; int num2 = 100; // Type cast integers to short int before addition short int result = (short int)(num1 + num2); printf("Result: %d\n", result); return 0; } Explanation: In this example, we have two integers num1 and num2. Before performing the addition, we type-cast the result of num1 + num2 to a short int using (short int) to fit the result within the range of a short int. |