Difference between revisions of "CSC231 Mystery C Program with signed numbers"

From dftwiki3
Jump to: navigation, search
(New page: Back to weekly schedule --- =Mystery Program= Figure out what the two variables x and y are initialized with when the program starts. <code><pre> /* mystery...)
 
Line 1: Line 1:
[[CSC231_Weekly_Schedule | Back]] to weekly schedule
+
[[SC231_Class_Page Back]] to weekly schedule
 
---
 
---
 
=Mystery Program=
 
=Mystery Program=

Revision as of 11:16, 24 September 2008

SC231_Class_Page Back to weekly schedule ---

Mystery Program

Figure out what the two variables x and y are initialized with when the program starts.

/* mystery.cpp
// D. T.
// mystery program
// To compile and run this program:
//
//     g++ mystery.cpp
//     a.out
//
// The output of the program is the following
//
// 32740
// -32756
//
// With what positive values were x and y initialized
// at the beginning of the program.  Explain why.
// (a short int contains 16 bits)
*/

#include <stdio.h>

main() {

    short int x = ???? ;
    short int y = ???? ;

    x = x+y;
    printf( "%d\n", x );

    x = x+y;
    printf( "%d\n", x );
}