Question
Consider the following C code: #include
#include int main() {   char str1[] = "Hello";   char str2[] = {'W', 'o', 'r', 'l', 'd', '\0', 'X'};   char str3[] = {'C', 'o', 'd', 'e'}; // No null terminator   printf("%zu %zu\n", strlen(str1), strlen(str2));   // What happens if strlen(str3) is called?   // printf("%zu\n", strlen(str3));   return 0; } What will be the output of the printf statement, and what would be the behavior if strlen(str3) were uncommented and executed?Solution
Correct Answer: B (strlen(str1) is 5. strlen(str2) counts up to the first \0, so 5. strlen(str3) would read past the allocated memory until it finds a \0, leading to undefined behavior (segmentation fault or garbage value).)
- Find the wrong number in the given number series.
10, 13, 17, 24, 31, 41 9, 10, 12, 18, 42, 160
2, 9, 32, 87, 198, 387
Find the wrong number in the series.
5, 12, 23, 38, 57, 80, 107768Â Â Â 2304Â Â Â 288Â Â Â 864Â Â Â 106Â Â Â 324
Find the wrong number in the given number series.
13, 20, 31, 44, 62, 80
12, 18, 40, 90, 270, 945
Find the wrong number in the given number series.
5, 6, 14, 45, 188, 925
154Â Â Â Â 165Â Â Â Â 143Â Â Â Â 175Â Â Â Â Â 132Â Â Â Â Â 187
...- 12.8, 17.4, 22, 26.6, 31.2, 36.8