CpSc 1010 Computer Programming I

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Look over the code and table below and answer the question that follows. 1 #include <stdio.h> 2 3 int main( ) { 4 int integer1, *p1, *p2; 5 6 integer1 = 10; 7 p1 = &integer1; 8 p2 = &p1; 9 10 (*p1)++; 11 printf("%d\n", integer1); 12 printf("%p\n", p1); 13 printf("%p\n", p2); 14 return 0; 15 } Name Type Address integer1 int 0x7fff8c1ff994 p1 int * 0x7fff8c1ff988 p2 int ** 0x7fff8c1ff980 With the added line of code on line 10, what would be the output printed from line 11?

11

What value is printed by the print statement below? #include <stdio.h> int square(int x); int main(void) { int value = 2; int valueSquared = square(value); printf("%d\n", square(4)); return 0; } int square(int x) { return x * x; }

16

Answer the question below, which pertain to this code: int x[ ] = { 1, 2, 3, 4 }; int * p = &x[2]; int * q = &x[1]; int * r = q++; What would be printed after this statement: printf( "%i \n", *r );

2

Consider the program below and fill in the missing code. #include <stdio.h> // 1. define a structure called dob that contains an array for month, // an integer for day, and an integer for year int main(int argc, char *argv[]) { // 2. declare a variable bday whose type is the structure dob // show scanf() statements to get the values entered by the // user into the variable bday: printf("Enter your birthmonth (3 letter month abbreviation);"); // 3. scanf() for month: printf("Enter an integer for your birth day: "); // 4. scanf() for day: printf("Enter an integer for your birth year: "); // scanf() for year: // 5. finish the printf statement below printf("Your birthday is: %s %d, %d\n", ___________________ ); return 0; }

typedef struct { char month[4]; int day, year; } dob;

What value is printed by the print statement below? #include <stdio.h> int square(int x); int main(void) { int value = 2, x; int valueSquared = square(value); square(4); printf("%d \n", x); return 0; } int square(int x) { return x * x; }

undefined value

Assume you have a program with the following structure definition for a month typedef struct { int numberOfDays; char monthName[4]; } month; and an array of 12 of these months declared and initialized like the following: month months[12] = { {31, "Jan"}, {28, "Feb"}, {31, "Mar"}, {30, "Apr"}, {31, "May"}, {30, "Jun"}, {31, "Jul"}, {31, "Aug"}, {30, "Sep"}, {31, "Oct"}, {30, "Nov"}, {31, "Dec"} }; What would a prototype for a function that would print this array of months look like? The function will not be returning anything, it will be taking in an array of months called theMonths as a parameter, and it will be called printMonths

void printMonths(month theMonths[ ]);

What value is printed by the print statement below? #include <stdio.h> int square(int x); int main(void) { int value = 2; int valueSquared = square(value); square(4); printf("%d \n", x); return 0; } int square(int x) { return x * x; }

won't compile

Look over the code and table below and answer the question that follows. 1 #include <stdio.h> 2 3 int main( ) { 4 int integer1, *p1, *p2; 5 6 integer1 = 10; 7 p1 = &integer1; 8 p2 = &p1; 9 10 printf("%d\n", integer1); 11 printf("%p\n", p1); 12 printf("%p\n", p2); 13 return 0; 14 } Name Type Address integer1 int 0x7fff8c1ff994 p1 int * 0x7fff8c1ff988 p2 int ** 0x7fff8c1ff980 The item at memory address 0x7fff8c1ff980 holds what value?

0x7fff8c1ff988

Look over the code and table below and answer the question that follows. 1 #include <stdio.h> 2 3 int main( ) { 4 int integer1, *p1, *p2; 5 6 integer1 = 10; 7 p1 = &integer1; 8 p2 = &p1; 9 10 printf("%d\n", integer1); 11 printf("%p\n", p1); 12 printf("%p\n", p2); 13 return 0; 14 } Name Type Address integer1 int 0x7fff8c1ff994 p1 int * 0x7fff8c1ff988 p2 int ** 0x7fff8c1ff980 The item at memory address 0x7fff8c1ff988 holds what value?

0x7fff8c1ff994

What will be printed out by the program below? #include <stdio.h> void auto_static (void) { int autoVar = 1; static int staticVar = 1; printf("%i, %i\n", autoVar, staticVar); ++autoVar; ++staticVar; } int main (void) { int i; for( i = 0; i < 5; ++i ) auto_static(); return 0; }

1, 1 1, 2 1, 3

Look over the code and table below and answer the question that follows. 1 #include <stdio.h> 2 3 int main( ) { 4 int integer1, *p1, *p2; 5 6 integer1 = 10; 7 p1 = &integer1; 8 p2 = &p1; 9 10 printf("%d\n", integer1); 11 printf("%p\n", p1); 12 printf("%p\n", p2); 13 return 0; 14 } Name Type Address integer1 int 0x7fff8c1ff994 p1 int * 0x7fff8c1ff988 p2 int ** 0x7fff8c1ff980 The item at memory address 0x7fff8c1ff994 holds what value?

10

2. What value is printed with the second print statement? #include <stdio.h> void f1(float x) { int n = 6; printf("%f \n", x + n); } int f2(void) { float n = 10; printf("%.2f \n", n); // 2. what value is printed here? } int main(void) { int n = 5; f1(3); f2(); return 0; }

10.00

4. What values are printed from the program below? (Don't add any extra spaces in between the values). #include <stdio.h> void multiplyBy2(float array[], int n) { int i; for( i = 0; i < n; ++i ) array[i] *= 2; } int main(void) { float floatVals[4] = { 1.2, -3.3, 6.1, 8.4 }; int i; multiplyBy2 (floatVals, 4); for( i = 0; i < 4; ++i ) printf("%.2f ", floatVals[i]); // What values are printed here? printf("\n"); return 0; }

2.40 -6.60 12.20 16.80

Answer the question below, which pertain to this code: int x[ ] = { 1, 2, 3, 4 }; int * p = &x[2]; int * q = &x[1]; int * r = q++; What would be printed after this statement: printf( "%i \n", *q );

3

Answer the question below, which pertain to this code: int x[ ] = { 1, 2, 3, 4 }; int * p = &x[2]; int * q = &x[1]; int * r = q++; What would be printed after this statement: printf( "%i \n", *(p+1) );

4

What value is printed with the print statement below? #include <stdio.h> int x = 2; void f1(int x) { x++: } void f2(void) { x++; } int main(void) { int x = 7; f1(x); f2(); printf("%i \n", x); // What value is printed here? }

7

3. What value is printed with the print statement below? #include <stdio.h> void multiplyBy2(float y) { y *= 2; } int main(void) { float y = 7; multiplyBy2(y); printf("%.2f \n", y); // What value is printed here? return 0; }

7.00

1. What value is printed with the first print statement? #include <stdio.h> void f1(float x) { int n = 6; printf("%f \n", x + n); // 1. what value is printed here? } int f2(void) { float n = 10; printf("%.2f \n", n); } int main(void) { int n = 5; f1(3); f2(); return 0; }

9.000000

Review the code below. What would be printed by the printf( ) statement. #include <stdio.h> void swap(int int); int main(void) { // declare two integers int a = 5; int b = 6; // swap the two values so that a becomes 6 and b becomes 5 swap(a, b); printf("a is %d and b is %d\n", a, b); return 0; } void swap(int first, int second) { int temp; temp = first; first = second; second = temp; }

a is 5 and b is 6

Consider the program below and fill in the missing code. #include <stdio.h> // 1. define a structure called dob that contains an array for month, // an integer for day, and an integer for year int main(int argc, char *argv[]) { // 2. declare a variable bday whose type is the structure dob // show scanf() statements to get the values entered by the // user into the variable bday: printf("Enter your birthmonth (3 letter month abbreviation);"); // 3. scanf() for month: printf("Enter an integer for your birth day: "); // 4. scanf() for day: printf("Enter an integer for your birth year: "); // scanf() for year: // 5. finish the printf statement below printf("Your birthday is: %s %d, %d\n", ___________________ ); return 0; }

bday.month, bday.day, bday.year

Assume you have a program with the following structure definitions: typedef struct { int month, day, year; } date; typedef struct { int hour, minutes, seconds; } time; typedef struct { date sdate; time stime; } dateAndTime; How would you declare a variable of type dateAndTime called event?

dateAndTime event;

Consider the program below and fill in the missing code. #include <stdio.h> // 1. define a structure called dob that contains an array for month, // an integer for day, and an integer for year int main(int argc, char *argv[]) { // 2. declare a variable bday whose type is the structure dob // that was defined with typedef // show scanf() statements to get the values entered by the // user into the variable bday: printf("Enter your birthmonth (3 letter month abbreviation);"); // 3. scanf() for month: printf("Enter an integer for your birth day: "); // 4. scanf() for day: printf("Enter an integer for your birth year: "); // scanf() for year: // 5. finish the printf statement below printf("Your birthday is: %s %d, %d\n", ___________________ ); return 0; }

dob bday;

Assume you have a program with the following structure definitions: typedef struct { int month, day, year; } date; typedef struct { int hour, minutes, seconds; } time; typedef struct { date sdate; time stime; } dateAndTime; and a variable of type dateAndTime called event How would you assign the value 10 to the month value of event?

event.sdate.month = 10;

Look over the code and table below and answer the question that follows. 1 #include <stdio.h> 2 3 int main( ) { 4 int integer1, *p1, *p2; 5 6 integer1 = 10; 7 p1 = &integer1; 8 p2 = &p1; 9 10 *p1++; // is this line of code the same as: (*p1)++; 11 printf("%d\n", integer1); 12 printf("%p\n", p1); 13 printf("%p\n", p2); 14 return 0; 15 } Name Type Address integer1 int 0x7fff8c1ff994 p1 int * 0x7fff8c1ff988 p2 int ** 0x7fff8c1ff980 With the added line of code on line 10, would the output printed from line 11 be "11"?

no

Assume you have a program with the following structure definitions: typedef struct { int month, day, year; } date; typedef struct { int hour, minutes, seconds; } time; typedef struct { date sdate; time stime; } dateAndTime; and a variable of type dateAndTime called event Could you use the following line to increment the seconds by 1? event.time.seconds += 1;

no, not correct

Assume you have a program with the following structure definitions: typedef struct { int month, day, year; } date; typedef struct { int hour, minutes, seconds; } time; typedef struct { date sdate; time stime; } dateAndTime; and a variable of type dateAndTime called event Could you use the following line to increment the seconds by 1? event.time.seconds = event.time.seconds + 1;

no, not correct

Consider the program below and fill in the missing code. #include <stdio.h> // 1. define a structure called dob that contains an array for month, // an integer for day, and an integer for year int main(int argc, char *argv[]) { // 2. declare a variable bday whose type is the structure dob // show scanf() statements to get the values entered by the // user into the variable bday: printf("Enter your birthmonth (3 letter month abbreviation);"); // 3. scanf() for month: printf("Enter an integer for your birth day: "); // 4. scanf() for day: printf("Enter an integer for your birth year: "); // scanf() for year: // 5. finish the printf statement below printf("Your birthday is: %s %d, %d\n", ___________________ ); return 0; }

scanf("%d", &bday.day);

Consider the program below and fill in the missing code. #include <stdio.h> // 1. define a structure called dob that contains an array for month, // an integer for day, and an integer for year int main(int argc, char *argv[]) { // 2. declare a variable bday whose type is the structure dob // show scanf() statements to get the values entered by the // user into the variable bday: printf("Enter your birthmonth (3 letter month abbreviation);"); // 3. scanf() for month: printf("Enter an integer for your birth day: "); // 4. scanf() for day: printf("Enter an integer for your birth year: "); // scanf() for year: // 5. finish the printf statement below printf("Your birthday is: %s %d, %d\n", ___________________ ); return 0; }

scanf("%s", bday.month);

Assume you have a program with the following structure definition for a date struct date { int month, day, year; }; and a function that updates the date sent in as a parameter to tomorrow's date, and returns tomorrow's date. The function body is shown below. What would the missing function header look like? missing function header here { struct date tomorrow; tomorrow.day = today.day + 1; tomorrow.month = today.month; tomorrow.year = today.year; return tomorrow; }

struct date dateUpdate(struct date today)

What value is printed with the first print statement below? #include <stdio.h> int x = 2; void f1(int x) { x++; f2(); } void f2(void) { x++; printf("x=%i \n",x); // What prints here? } int main(void) { int x = 7; f1(x); printf("x=%i \n",x); }

x=3

Look over the code and table below and answer the question that follows. 1 #include <stdio.h> 2 3 int main( ) { 4 int integer1, *p1, *p2; 5 6 integer1 = 10; 7 p1 = &integer1; 8 p2 = &p1; 9 10 integer1++; // is this line of code the same as: (*p1)++; 11 printf("%d\n", integer1); 12 printf("%p\n", p1); 13 printf("%p\n", p2); 14 return 0; 15 } Name Type Address integer1 int 0x7fff8c1ff994 p1 int * 0x7fff8c1ff988 p2 int ** 0x7fff8c1ff980 With the added line of code on line 10, would the output printed from line 11 be "11"?

yes

Assume you have a program with the following structure definitions: typedef struct { int month, day, year; } date; typedef struct { int hour, minutes, seconds; } time; typedef struct { date sdate; time stime; } dateAndTime; and a variable of type dateAndTime called event Could you use the following line to increment the seconds by 1? ++event.stime.seconds;

yes, correct

Assume you have a program with the following structure definitions: typedef struct { int month, day, year; } date; typedef struct { int hour, minutes, seconds; } time; typedef struct { date sdate; time stime; } dateAndTime; and a variable of type dateAndTime called event Could you use the following line to increment the seconds by 1? event.stime.seconds += 1;

yes, correct

Assume you have a program with the following structure definitions: typedef struct { int month, day, year; } date; typedef struct { int hour, minutes, seconds; } time; typedef struct { date sdate; time stime; } dateAndTime; and a variable of type dateAndTime called event Could you use the following line to increment the seconds by 1? event.stime.seconds = event.stime.seconds + 1;

yes, correct

Assume you have a program with the following structure definitions: typedef struct { int month, day, year; } date; typedef struct { int hour, minutes, seconds; } time; typedef struct { date sdate; time stime; } dateAndTime; and a variable of type dateAndTime called event Could you use the following line to increment the seconds by 1? event.stime.seconds++;

yes, correct


संबंधित स्टडी सेट्स

Mesopotamia: The Land Between Two Rivers

View Set

The Real World: An Introduction to Society Chapter 3

View Set

Med-Surg Ch. 53 EAQ: Sexually Transmitted Infections

View Set

Physics I Concept Questions: Exam 1

View Set

Computer Organization, csc 3210, CSC 3210, CSC 3210 - Georgia State University - Chen Xucan, Test One Review, Computer organization and assembly language programming-Module 4: Data Representation, CS2640: Computer Organization and Assembly Programmin...

View Set