Interview Question: Short Mystery

Sample Question #226 (programming – C)

Why doesn’t the following C code work?

short int s;
scanf("%d", &s);
 
Advertisements
This entry was posted in Sample Qs. Bookmark the permalink.

One Response to Interview Question: Short Mystery

  1. Brett says:

    ANSWER
     
    Since s is a short int, you need to use "%hd" to read it in, not "%d" which is for regular int.
     
    (BTW, C is still used widely on Wall Street, esp. in a lot of legacy modeling codebases, although C++ and C# are definitely taking over the world.)
     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s