M3: Quiz

Ace your homework & exams now with Quizwiz!

A pointer variable can take the address of a memory location as its value. Read the given program. The output of the 1st printf statement is [ Select ] ["100", "90", "80", "30", "60", "40"] . a) 100 b) 90 c) 80 d) 60

a) 100

A pointer variable can take the address of a memory location as its value. Read the given program. The output of the 3rd printf statement is __ . a) 30 b) 40 c) 60 d) 80

a) 30

Given the following C code: char a[2][3] = { { 'c', 'a', 't'}, { 'd', 'o', 'g'} }; int i, j; for (i = 0; i<2 ; i++) { for (j = 0; j<3; j++) printf("%c", a[i][j]);} What will happen? a) It prints: catdog b) A compilation error will occur at this line: char a[2][3] = { { 'c', 'a', 't'}, { 'd', 'o', 'g'} }; c) It prints: cat d) A compilation error will occur at this line: printf("%c", a[i][j]);

a) It prints: catdog

Given this snippet of code, determine which of the following options will change the text in array to "Hello Doe" after execution. (Check all that apply.) char array[] = "Hello Joe"; char *x; a) x = array; x = x + 6; x = 'D'; b) x = &array; x = x + 6; x = 'D'; c) x = array; *(x + 6) = 'D'; d) x = &array[0]; x = x + 6; *x = 'D';

c) x = array; *(x + 6) = 'D'; d) x = &array[0]; x = x + 6; *x = 'D';

Given the following snippet of code, answer the following question based on the code: typedef enum {Sun, Mon, Tue, Wed, Thu, Fri, Sat} days; days x = Mon, y = Sat; while (x != y) { x++; } y++; printf("x = %d, y = %d", x, y); What value will be printed for variable x? a) Mon b) 0 c) Sat d) 6

d) 6

A pointer variable can take the address of a memory location as its value. Read the given program. The output of the 2nd printf statement is [ Select ] ["100", "60", "90", "80", "30", "40"] . a) 30 b) 40 c) 60 d) 80

d) 80

Given the following snippet of code, answer the following question based on the code: typedef enum {Sun, Mon, Tue, Wed, Thu, Fri, Sat} days; days x = Mon, y = Sat; while (x != y) { x++; } y++; printf("x = %d, y = %d", x, y); What value will be printed for variable y? a) Error b) 7 c) Sun d) 6

b) 7

C/C++ has 2 pointer operators, which operator represents using the value at the location given by an address? a) Ampersand (&) b) Asterisk (*) c) Comma (,) d) Semicolon (:)

b) Asterisk (*)

Given the following code: char a[2][4] = { { 'c', 'a', 'r', 'b' }, { 'i', 'k', 'e', '\0' } }; char *p = &a[0][0]; while (*p != '\0'){ printf("%c", *p); p++; } What will happen? a) A compilation error will occur at this line: while (*p != '\0') b) It prints: carbike c) A compilation error will occur at this line: char *p = &a[0][0]; d) It prints: carb

b) It prints: carbike

Given the following definition and declarations: #define size1 10 const int size2 = 20; char a1[size1]; char a2[size2]; which line is most likely to cause a compilation error? a) both char a1[size1] and char a2[size2]; b) char a2[size2]; c) char a1[size1]; d) const int size2 = 20;

b) char a2[size2];

When using an array of structures to store a collection, we typically have a variable storing the number of entries (called something like: tail, count, or size). In addition to the number of entries, what does this variable help to indicate? The tail variable in an array of structures is used for indicating (Select all that apply) a) the starting address of the array. b) how far the search() function should go in searching the items of the array. c) where to insert a new item, if the items in the array do not need to be sorted. d) where to delete an existing item in the array.

b) how far the search() function should go in searching the items of the array. c) where to insert a new item, if the items in the array do not need to be sorted.

Given this snippet of code, what is the value of x after executing the last statement? int x = 10, *y; y = &x; *y = 100; y = y + 1; a) None of these values. b) 1000 c) 100 d) 10

c) 100

Given the following code char a[] = {'c', 'a', 't', '\0'}; char *p = a; while (*p != 0) { *p = *p + 1; printf("%c", *(p++)); } What will happen? a) It prints: cat b) It prints: a string of random characters c) It prints: dbu d) A run time error will occur at the printf line.

c) It prints: dbu

Given the declaration: char A[3] = {'C', 'a', 'r'}, *p = A; what statement prints character a? a) printf("%c", *p); b) printf("%c", *p+1); c) printf("%c", *(++p)); d) printf("%c", *p++);

c) printf("%c", *(++p));

Consider the following snippet of code in a 32-bit computer. #define MAX 10 struct contact { char name[30]; char email[30]; int phone; }; struct contact contactbook[MAX]; int tail = 0; Which statement can read a name into the name field of the structure? a) scanf("%s", &contactbook.name); b) scanf("%s", contactbook.name); c) scanf("%s", contactbook[tail].name); d) scanf("%s", &contactbook[tail].name);

c) scanf("%s", contactbook[tail].name);


Related study sets

5.3 Given a scenario, use the appropriate network software tools and commands.

View Set

Activity Questions: Chapters 5, 6, 7, 8, 10

View Set

Firewalls, Encryption, Hashing Algorithms

View Set

BUSN 101 CH 7: Operations Management and Quality

View Set

A+ 901-1.15-(1)- Given a scenario, perform appropriate printer maintenance.

View Set