Difference between revisions of "CSC231 Mystery C Program Solution"

From dftwiki3
Jump to: navigation, search
(New page: Back to Weekly Schedule ---- <code><pre> /* mystery.cpp // D. T. // mystery program // To compile and run this program: // // g++ mystery.cpp // a.out //...)
 
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[CSC231_Class_Page | Back ]] to Weekly Schedule
+
--[[User:Thiebaut|D. Thiebaut]] 14:10, 8 October 2010 (UTC)
 +
----
 +
 
 +
 
  
----
 
  
<code><pre>
+
<source lang="cpp">
 
/* mystery.cpp
 
/* mystery.cpp
 
// D. T.
 
// D. T.
Line 24: Line 26:
 
#include <stdio.h>
 
#include <stdio.h>
  
main() {
+
int main() {
  
     short int x = 32700 ;
+
     //short  
     short int y = 40 ;
+
    int x = 32700 ;
 +
     //short  
 +
    int y = 40 ;
  
 
     x = x+y;
 
     x = x+y;
Line 34: Line 38:
 
     x = x+y;
 
     x = x+y;
 
     printf( "%d\n", x );
 
     printf( "%d\n", x );
 +
 +
    return 0;
 
}
 
}
  
  
</pre></code>
+
</source>
 +
 
 +
<br />
 +
 
 +
<br />
 +
 
 +
<br />
 +
 
 +
<br />
 +
 
 +
<br />
 +
 
 +
<br />
 +
[[Category:CSC231]][[Category:C]]

Latest revision as of 12:27, 13 November 2014

--D. Thiebaut 14:10, 8 October 2010 (UTC)




/* 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>

int main() {

    //short 
    int x = 32700 ;
    //short 
    int y = 40 ;

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

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

    return 0;
}