Difference between revisions of "CSC231 Mystery C Program with signed numbers"
Line 53: | Line 53: | ||
<br /> | <br /> | ||
<br /> | <br /> | ||
+ | <br /> | ||
<br /> | <br /> | ||
<br /> | <br /> | ||
Line 62: | Line 63: | ||
<br /> | <br /> | ||
<br /> | <br /> | ||
+ | |||
+ | [[CSC231_Mystery_C_Program_Solution | Solution]]! | ||
+ | |||
<br /> | <br /> | ||
+ | <br /> | ||
<br /> | <br /> | ||
− | + | [[Category:CSC231]][[Category:C++]] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | [[ |
Revision as of 09:12, 8 October 2010
Back to weekly schedule
Mystery Program
Figure out what the two variables x and y are initialized with when the program starts.
You may use this converter to help you out...
/* 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 );
}