GoConqr has a new look! Let us know what you think.

Quiz

Pointers and dynamic memory: leaks and argv

Christian Farris 3 questions

Take the quiz

This quiz has question types that open in the usual player.

Questions in this quiz (3)

  1. 1Which of the following code fragments causes a memory leak?
    1. Aint *p = malloc(sizeof(int));
      int *q = malloc(sizeof(int));
      free(p);
      q = p;
      p = NULL;
    2. Bint *p = malloc(sizeof(int));
      int *q = NULL;
      q = p;
      p = malloc(sizeof(int));
    3. Cint *p = malloc(sizeof(int));
      int *q = p;
      free(p);
      q = malloc(sizeof(int));
    4. Dint *p = NULL;
      int *q = malloc(sizeof(int));
      p = q;
      free(q);
      p = malloc(sizeof(int));
    5. Eint *p = malloc(sizeof(int));
      int *q = NULL;
      q = p;
      p = NULL;
  2. 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]
    1. A*
    2. B3
    3. C5
  3. 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] .
    1. A11
    2. B0x_0c0

Information

Description
Quiz on Untitled, created by Christian Farris on 28/04/2018.
Language
English
Views
0
Rating
No ratings yet
Rate this quiz
Rate this quiz

Feedback

What is it about?

What do you think of the new look?

How do you like it?