Mcq modul 04
Correct ans.

HOME
Question 1
/ 1 pts
The memory block allocated by malloc() function:
  
is filled with zeros

Correct!
  
is filled with random values

  
is filled with 0xdeadbeef

  
is filled with 0xFF


Question 2
/ 1 pts
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);
printf("%d\n", p != q);
return 0;
}
  
the code will cause runtime error

  
the output cannot be determined

  
1

Correct!
  
0


Question 3
/ 1 pts
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;
}
  
112345

  
the output cannot be determined

Correct!
  
122345

  
011345


Question 4
/ 1 pts
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", memcmp(p1,p2,8));
return 0;
}
  
the output is unpredictable

  
an int value greater than 0

  
an int value less than 0

Correct!
  
an int value equal to 0


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

  
2

  
0

Correct!
  
-2


Question 6
/ 1 pts
Passing the NULL as the first strtok() argument causes
  
the functions to iterate through the string

  
the function to restart the find process

Correct!
  
the function to repeat last find

  
runtime error


Question 7
/ 1 pts
The following declarator declares the compar symbol as:
void (*compar)(int*, int*);
  
a pointer to array containing ints

  
a void pointer

  
a pointer to function returning int

Correct!
  
a pointer to function returning void


Question 8
/ 1 pts
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);
}
  
random


the resulting sort order could not be determined

Correct!
  
non-ascending

  
non-descending


Question 9
/ 1 pts
The Unicode code point of value equal to 32:
Correct!

denotes the same character as ASCII character of the same value

denotes the character depending on target code page
  
may not be used in a source code

  
does not exist


Question 10
/ 1 pts
The value of the following expression:
sizeof(wchar_t) <= sizeof(wint_t)
  
depends on target platform

  
is always 0

  
cannot be determined

Correct!
  
is always 1


Question 11
/ 1 pts
The address of memory block allocated by malloc() function:
Correct!

is aligned but the alignment is implementation specific
  
is completely random

  
is aligned to double data type

  
is aligned to long long int data type


Question 12
/ 1 pts
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;
}
  
0

Correct!
  
the code will cause runtime error

  
the output cannot be determined

  
1


Question 13
/ 1 pts
The following calloc() invocation allocates:
void *p = calloc(10, 1);

allocates 1 byte long block aligned to 10 bytes boundary
Correct!
  
allocates 10 occurrences of 1 byte long block


allocates 10 byte long block aligned to 1 byte boundary
  
allocates 1 occurrence of 10 byte long block


Question 14
/ 1 pts
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 greater than 0

Correct!
  
an int value less than 0

  
an int value equal to 0


the output depends on target platform's endianess


Question 15
/ 1 pts
The following code will output 2 when you assign the off variable with the value of:
#include <string.h>
#include <stdio.h>
int main(void) {
char p[] = "10110110";
int off = >;
printf("%ld\n", strstr(p, p + off) - p);
return 0;
}
Correct!
  
5

  
7

  
4

  
6


Question 16
/ 1 pts
The second strtok() function's parameter (named delim) is:
  
a string taken as a whole (char *)

Correct!
  
a set of characters stored as a string (char *)

  
a character

  
an int


Question 17
/ 1 pts
Which declarator will you use to declare fun as a pointer to 2 parameter function (one int and one float) returning pointer to char?
  
char (*fun)(int,float)

  
char *(fun)(int,float)

Correct!
  
char *(*fun)(int,float)

  
char (fun)(int,float)


Question 18
/ 1 pts
To find an element with the key field equal to "key" through the arr you will use the bsearch() function with the following comparator:
struct Str {
char key[8\];
} arr[10\];
Correct!

int cmp(const void *v1, const void *v2) { return strcmp(((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 ((Str *) v1)->key - ((Str *) v2)->key; }

int cmp(const void *v1, const void *v2) { return strcmp(v1.key, v2.key); }

Question 19
/ 1 pts
To store UNICODE code points the UTF-8 uses:

number of bits depending on target platform's word length
Correct!
  
varying number of bits

  
target code page encoding

  
constant number of bits


Question 20
/ 1 pts
To specify any of UNICODE characters the following syntax may be used:
  
W'x'

  
w'x'

  
l'x'

Correct!
  
L'x'