M4: Quiz

The size (number of bytes) of a structure-type variable can be changed by the following factors. Select all that apply.

a) changing the computer from a 32-bit to a 64-bit processor.
b) changing the orders of the members in the structure.
c) adding a member into the structure.
d) changing a struct from containing one char followed by a int, to a two chars followed by an int.
Click the card to flip 👆
1 / 15
Terms in this set (15)
The size (number of bytes) of a structure-type variable can be changed by the following factors. Select all that apply.

a) changing the computer from a 32-bit to a 64-bit processor.
b) changing the orders of the members in the structure.
c) adding a member into the structure.
d) changing a struct from containing one char followed by a int, to a two chars followed by an int.
Which of the following coding practices can lead to a higher memory efficiency (i.e., fewer padding bytes) in defining a structure?

a) The order of the members in a strucuture does not increase or decrease the structure size.
b) Keep the character type variables together.
c) Place word-type variables (such as int, float, pointer) between the character-type variables.
d) Keep the word-type variables together.
Given the information below, how will you access the name of the third terminal node in the linked list? Assume head is pointing to the first terminal node and there are at least 3 terminals in the linked list.

struct Terminal {
char name[30];
char location[32];
struct Terminal* next;
};
struct Terminal *head;

a) Terminal[2]->name;
b) Terminal[2].name;
c) head->next->next->next->name;
d) head->next->next->name;
Given the information below, how do you insert a new node, p, to the beginning of a linked-list. Assume head is pointing to the first node in the linked-list. Make sure that no nodes are lost.

struct Terminal {
char name[30];
char location[32];
struct Terminal* next;
} head, p;

a) head = p;
p->next = head;

b) p->next = head;
head = p;

c) head = p;

d) p->next = head;
Given the information below, which of the following snippet of codes will insert a new node in the second place in the linked list. Note that name and location won't be set up - the code is intended to only add a new node. Assume that the head variable will store the first node in the linked list and that it already contains at least one node. struct Terminal { char name[30]; char location[32]; struct Terminal* next; } *head, *p, *q; a) p = (struct contact *) malloc(sizeof(struct contact)); head = q; q->next = p; while(q != NULL) q = q->next; b) p = (struct contact *) malloc(sizeof(struct contact)); head = q; while(q != NULL) q = q->next; q->next = p; c) p = (struct contact *) malloc(sizeof(struct contact)); p->next = head; head = p; d) p = (struct contact *) malloc(sizeof(struct contact)); p->next = head->next; head->next = p;d) p = (struct contact *) malloc(sizeof(struct contact)); p->next = head->next; head->next = p;Given the snippet of codes, identify the passing mechanism used for y (in func). void func(int *x, int &y) { *x = *x + y; y = 2; } a) pass-by-alias b) pass-by-address c) pass-by-pointer d) pass-by-valuea) pass-by-aliasWhich of the following statements is true? a) A global variable cannot be used as the actual parameter for pass-by-alias. b) The return value of a function cannot be a pointer. c) A constant cannot be used as the actual parameter for pass-by-alias. d) A constant cannot be used as the actual parameter for pass-by-address.c) A constant cannot be used as the actual parameter for pass-by-alias.Given this snippet of codes, what is the expected output? void func(int *x, int y){ *x = *x + y; y = 2; } void main(){ int x = 10, y = 10; func(&x, y); printf("x: %d, y: %d", x, y); } a) x: 20, y: 20 b) x: 20, y: 2 c) x: 10, y: 10 d) x: 20, y: 10d) x: 20, y: 10Given this snippet of codes, what is the expected output? void func(int *x, int y){ *x = *x + y; x = 10; } void main(){ int x = 10, y = 10; func(&x, y); printf("x: %d, y: %d", x, y); } a) x: 20, y: 10 b) x: 20, y: 20 c) x: 10, y: 10 d) x: 23430, y: 23434a) x: 20, y: 10