Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Type casting with short int in C
#1
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.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Comparisons with short int in C Qomplainerz 0 264 07-26-2023, 03:51 PM
Last Post: Qomplainerz
  User input and short int conversion in C Qomplainerz 0 264 07-26-2023, 03:49 PM
Last Post: Qomplainerz
  Overflow and underflow with short int in C Qomplainerz 0 257 07-26-2023, 03:48 PM
Last Post: Qomplainerz
  Arithmetic operations with short int in C Qomplainerz 0 272 07-26-2023, 03:46 PM
Last Post: Qomplainerz
  Storing short integers in C Qomplainerz 0 259 07-26-2023, 03:45 PM
Last Post: Qomplainerz
  Implicit and explicit type conversion in C Qomplainerz 0 252 07-26-2023, 08:25 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 1 Guest(s)