M3: Quiz

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 (:)
Click the card to flip 👆
1 / 15
Terms in this set (15)
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';
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
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]);
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];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) 6d) 6Given 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) 6b) 7When 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.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);