Quiz
Pointers and dynamic memory: leaks and argv
This quiz has question types that open in the usual player.
Questions in this quiz (3)
1Which of the following code fragments causes a memory leak?
- Aint *p = malloc(sizeof(int));
int *q = malloc(sizeof(int));
free(p);
q = p;
p = NULL; - Bint *p = malloc(sizeof(int));
int *q = NULL;
q = p;
p = malloc(sizeof(int)); - Cint *p = malloc(sizeof(int));
int *q = p;
free(p);
q = malloc(sizeof(int)); - Dint *p = NULL;
int *q = malloc(sizeof(int));
p = q;
free(q);
p = malloc(sizeof(int)); - Eint *p = malloc(sizeof(int));
int *q = NULL;
q = p;
p = NULL;
- Aint *p = malloc(sizeof(int));
2The following command is entered (where $ is the command prompt):
$a.out xyz1 bcde23 qrstuv456
Which replacements for X, Y and Z in the following statement will display only the letter v in the command above?
printf("%c\n", X(argv[Y] + Z));
X is [blank_start]*[blank_end]
Y is [blank_start]3[blank_end]
Z is [blank_start]5[blank_end]- A*
- B3
- C5
3#include <stdio.h>
int main(void) {
int i = 11;
int *ptr1 = &i;
int **ptr2 = &ptr1;
int ***ptr3 = &ptr2;
printf("%p, %p, %p, %p\n", ptr1, ptr2, ptr3, &ptr3);
return 0;
}
If the program output is (where _ is part of the address that is not shown):
0x_0b4, 0x_0b8, 0x_0c0, 0x_0c8
At address 0x_0b4 is stored [blank_start]11[blank_end] .
At address 0x_0c8 is stored [blank_start]0x_0c0[blank_end] .- A11
- B0x_0c0
Information
- Description
- Quiz on Untitled, created by Christian Farris on 28/04/2018.
- Author
- Christian Farris
- Language
- English
- Views
- 0
- Rating
- No ratings yet Rate this quiz