Last Updated on May 5, 2022 by Admin 2

Memory and Strings M4 Test

  1. The second strtok() function’s parameter (named delim) is:

    • a character
    • an int
    • a string taken as a whole(char *)
    • a set of characters stored as a string(char *)
  2. The following declarator declares the compare symbol as:

    void (*compar) (int*, int*);
    • a void pointer
    • a pointer to an array containing ints
    • a pointer to a function returning void
    • a pointer to a function returning an int
  3. To specify any UNICODE characters, the following syntax may be used:

    • W'x'
    • L'x'
    • l'x'
    • w'x'
  4. Passing NULLas the fisrt strtok() argument causes:

    • the function to restart the find process
    • a runtime error
    • the function to iterate through the string
    • the function to repeat the last find
  5. The value of the following expression:

    sizeof(wchar_t) <= sizeof(wint_t)
    • depends on the target platform
    • cannot be determined
    • is always 0
    • is always 1
  6. What is the expected output of the following code?

    #include <string.h>
    #include <stdio.h>
    int main(void) {
        char *p1 = malloc(8), *p2 = p1;
        printf("%d\n", memcump(p1,p2,8));
        return 0;
    }
    • an int value equal to 0
    • an int value greater than 0
    • an int value less than 0
    • the output is unpredictable
  7. To find an element with the key filed equal to key through the arr, you will use a bsearch() function with the following comparator:

    struct Str {
         chat key[8];
    } arr[10];
    • int cmp(const void *v1, const void *v2) { return ((Str) v1).key - ((Str) v2).key; }
    • int cmp(const void *v1, const void *v2) { return ((Str *) v1)->key - ((Str *) v2)->key;}
    • int cmp(const void *v1, const void *v2) { return strcmp(v1.key, v2.key); }
    • int cmp(const void *v1, const void *v2) { return strcmp((Str *) v1)->key, ((Str *) v1)->key, ((Str *) v2)->key); }
  8. The following calloc() invocation allocates:

    void *p = calloc(10, 1);
    • one occurrence of a 10-byte-long block
    • a 1-byte-long block aligned to a 10-byte boundary
    • ten occurrences of a 1-byte-long block
    • a 10-byte-long block aligned to a 1-byte boundary
  9. What is the expected output of the following code?

    #include <string.h>
    #include <stdio.h>
    int main(void) {
         char p[] = "101";
         printf("%1d\n", strchr(p, '1') - strrchr(p, '1'));
         return 0;
    }
    • -2
    • 2
    • 1
    • 0
  10. What is the expected output of the following code?

    #include <string.h>
    #include <stdio.h>
    int main(void) {
        char p[] = "012345";
        memmove(p, p + 1, 2);
        puts(p);
        return 0;
    } 
    • 011345
    • 112345
    • the output cannot be determined
    • 122345
  11. A​ memory block allocated by the malloc() function:

    • is filled with zeros
    • is filled with 0xFF
    • is filled with random values
    • is filled with 0xdeadbeef 
  12. What is the expected output of the following code?

    #include <stdlib.h>
    #include <stdio.h>
    int main(void) {
        char *p = malloc(1), *q = p;  
        free(q);
        free(p);
        printf("%d\n", p != q);
        return 0;
    }
    • 1
    • the output cannot be determined
    • the code will cause a runtime error
    • 0
  13. The Unicode code point of the value equal to 32:

    • denotes a character depending on the target code page
    • denotes the same character as the ASCII character of the same value
    • may not be used in a used in a source code
    • dose not exist
  14. The following code will output 2 when you assign the off variable with the value of:

    #include <stdlib.h>
    #include <stdio.h>
    int main(void) {
        char p[] = "10110110";  
        int off = <?>;
        printf("%d\n", strstr(p, p + off) - p);
        return 0;
    }
    • 4
    • 7
    • 5
    • 6
  15. To store UNICODE code points, the UTF-8 uses:

    • the target code page encoding 
    • a constant number of bits
    • a number of bits depending on the target platform’s word length
    • a varying number of bits
  16. The address of the memory block allocated by the malloc() function:

    • is aligned to a long long int​data type
    • is aligned, but the alignment is implementation specific
    • is aligned to a double data type
    • is completely random
  17. What is the expected output of the following code?

    #include <stdlib.h>
    #inclide <stdio,h>
    int main(void) {
        char *p = malloc(1), *q = p;  
        free(q);
        printf("%d\n", p != q);
        return 0;
    }
    • 1
    • the output cannot be determined
    • 0
    • the code will cause a runtime error
  18. Which declarator will you use to declare fun as a pointer to a two-parameter function (one int and one float) returning the pointer to char ?

    • char (*fun) (int, float)
    • char *(fun)(int,float)
    • char *(*fun)(int,float)
    • char (fun) (int,float)
  19. What is the expected output of the following code?

    #include <string.h>
    #include <stdio.h>
    int main(void) {
        unsigned i1 = 0x11223344, i2 = 0x12223344;
        printf("%d\n", memcmp(&i1,&i2,sizeof(unsigned)));
        return 0;
    }
    • an int value equal to 0
    • the output depends on the target platform’s endianness 
    • an int value greater than0
    • an int value less than0
  20. What will be the sort order if the qsort()function uses the following comparator?

    int cmp(const void *v1, const void *v2) {
       return *((int *) v2) - *((int *) v1);
    } 
    • the resulting sort order cannot be determined
    • non-ascending
    • non-descending
    • random