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).)
Sum of the three numbers is 180. Ratio of the first number to second number is 4:7 and the ratio of second number to third number is 7:9. Find the secon...
Two students appeared in an exam and one secured 18 marks more than the other. If marks of the student who got more marks is 58% of the sum of the marks...
A boy was asked to find 7/16 of a number. Instead, he found 3/4 of it. His answer was 110 greater than the correct answer. What is the number?
- If the 4-digit number a34b is exactly divisible by 9, what is the least value of (a + b)?
If the digits of a two-digit number are reversed, the resulting number is 36 less than twice the original number. If the sum of the digits is 9, what is...
- The sum of two numbers is 801. When the larger number is divided by the smaller one, it results in a quotient of 41 with a remainder of 3. What is the diff...
The value of √(56+√(56 +√(56+ √(56+√56+ ................ )) )) is
If z = 3 – 4i, find |z²|.
- A two-digit number has digits summing up to 10. On subtracting 36 from the number, the digits get interchanged. What is the original number?
Find the remainder when 2⁵ is divided by 7.