Unexpected Output When Using `printf` with `int` and `short` Types in C
I just started working with I'm collaborating on a project where I'm dealing with I've looked through the documentation and I'm still confused about I'm working with a strange scenario with `printf` when trying to output values of different types. I have the following code that is supposed to print an integer and a short value: ```c #include <stdio.h> int main() { int a = 100; short b = 50; printf("Integer: %d, Short: %d\n", a, b); return 0; } ``` When I run this, I expect to see: ``` Integer: 100, Short: 50 ``` but instead I see: ``` Integer: 100, Short: 0 ``` I checked the value of `b` before the `printf` call, and it correctly holds the value `50`. I've also tried using `%hi` for the short type, but that didn't work either. The compiler I'm using is GCC version 11.1 on Ubuntu 20.04. Could the scenario be related to the way `printf` handles the `short` type, or is there something else I'm overlooking? I've also tried compiling with different optimization flags, but the output remains the same. Any insights would be greatly appreciated! My development environment is Ubuntu. What's the best practice here? This is my first time working with C LTS. Any examples would be super helpful. This is for a application running on Linux. Is there a better approach? This is my first time working with C stable. What am I doing wrong? Cheers for any assistance! My team is using C for this web app. Thanks, I really appreciate it!