CSE1320Ch2Notes

CSE1320Ch2Notes - /* express.c, example 2-1, p. 60 */...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
1 /* express.c, example 2-1, p. 60 */ #include <stdio.h> main( ) { int x = 1, y, z; printf ("Value of x, %d\n", x); printf ("Value of 2*x + 5, %d\n", 2*x + 5); printf ("Value of assignment to x, %d\n", x = 5); printf ("Value of assignment to y, %d\n", y = 2*x++ + 1); printf ("x is %d and y is %d\n", x, y); z = y = 4*x + 5; printf ("y is %d and z is %d.\n", y, z); } OUTPUT: Value of x, 1 Value of 2*x + 5, 7 Value of assignment to x, 5 Value of assignment to y, 11 x is 6 and y is 11 y is 29 and z is 29.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 /* block.c, example 2-2, p. 64 */ #include <stdio.h> main( ) { int i = 3; { int i = 5; printf ("In the inner block, i is %d.\n", i); } printf ("In the outer block, i is %d.\n", i); } OUTPUT: In the inner block, i is 5. In the outer block, i is 3.
Background image of page 2
3 /* block2.c, example 2-3, p. 66 */ #include <stdio.h> main( ) { { int i; scanf( "%d", &i ); } printf( "i is %d.\n", i ); } OUTPUT: $ cc block2 printf( "i is %d.\n", i ); %CC-E-UNDECLARED, "i" is not declared within the scope of this usage. At line number 10 in USRB:[B705RLS.CH2]BLOCK2.C;2. } %CC-I-NOBJECT, No object file produced. At line number 11 in USRB:[B705RLS.CH2]BLOCK2.C;2. %CC-I-SUMMARY, Completed with 1 error(s), 0 warning(s), and 1 informational messages. At line number 11 in USRB:[B705RLS.CH2]BLOCK2.C;2.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 /* if1.c, example 2-4, p. 68 */ #include <stdio.h> #define CONST 5 int add_const( int ); main( ) { int sum, intvar; printf( "Enter a decimal integer: " ); scanf( "%d", &intvar ); sum = add_const( intvar ); printf( "%d + %d is %d.\n", intvar, CONST, sum ); if ( sum < 20 ) printf( "The number is small.\n" ); } /**************************************************************** The function 'add_const( )' accepts an integer argument 'intvar' and returns the sum of 'intvar' and the global constant 'CONST'.
Background image of page 4
5 ****************************************************************/ int add_const( int intvar ) { return( intvar + CONST ); } SAMPLE OUTPUT: Enter a decimal integer: 15 15 + 5 is 20. /* if2.c, example 2-5, pp. 70-71 */ #include <stdio.h> #define CONST 5 int add_const( int ); main( ) { int sum, intvar; printf( "Enter a decimal integer: " ); scanf( "%d", &intvar ); sum = add_const( intvar ); printf( "%d + %d is %d.\n", intvar, CONST, sum ); if ( sum < 20 ) printf( "The number is small.\n" ); else printf( "Oops, too big.\n" ); }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 /**************************************************************** The function 'add_const( )' accepts an integer argument 'intvar' and returns the sum of 'intvar' and the global constant 'CONST'. ****************************************************************/ int add_const( int intvar ) { return( intvar + CONST ); } SAMPLE OUTPUT: Enter a decimal integer: 15 15 + 5 is 20. Oops, too big. /* if3.c, example 2-6, pp. 72-73 */
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 23

CSE1320Ch2Notes - /* express.c, example 2-1, p. 60 */...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online