_BG_Test_2_Questions

_BG_Test_2_Questions - CIS 15BG 1 Test 2 Questions:...

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

View Full Document Right Arrow Icon
CIS 15BG Test 2 Questions: Chapters 8-12, 15, emphasizing 11, 12, and 15. "Computers are good at following instructions, but not at reading your mind." - Donald Knuth _____________________________________________________________________________________ 1. Pointers: Draw the memory map for the following program fragment. Predict the output. char ch1 = 'O'; char ch2 = 'B'; char *q; char *r; char **p; q = &ch2; r = &ch1; p = &q; printf( “%c %c %c\n”, *q, *r, **p ); *p = r; printf( “%c %c %c\n”, *q, *r, **p ); _____________________________________________________________________________________ 2 . Pointers and Arrays: Predict the output. // Local Declarations int list[100] = {10, 11, 30, 20, 15, 40, 25}; int length = 7; int *ptr; int num; // Statements for( ptr = list; ptr < list + length; ptr++ ) { *ptr = *ptr * 2 ; printf( “%d\n”, *ptr ); } _____________________________________________________________________________________ 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
CIS 15BG Test 2 Questions: Chapters 8-12, 15, emphasizing 11, 12, and 15. 3 . Strings and Pointers (A). Find the value of *x, *(x + 1), *x + 1, and *(x + 5) for the following declaration: char *x = "This is a beautiful day!" (B). What is the error in the following program fragment? How would you correct it? char *x = "This is a beautiful day!" char s[50]; s = x; (C). What is the mistake in the following program fragment? How would you correct it? char *x = "This is a beautiful day!" char *y = "This is a sunny day!"; if( x < y ) printf( "%s", x ); else if( x > y ) printf( "%s", y ); else printf("The two strings are identical!\n"); 2
Background image of page 2
CIS 15BG Test 2 Questions: Chapters 8-12, 15, emphasizing 11, 12, and 15. _____________________________________________________________________________________ 4 . Review Cohesion (729) and Coupling (A). Which one of the three good program design principles is not used in the following
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

_BG_Test_2_Questions - CIS 15BG 1 Test 2 Questions:...

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

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