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).)
Moody’s Projected India’s GDP growth forecast in FY22 at ?
Which bank recently received in-principle approval to set up an IBU in GIFT City, making it the first UAE-based bank to do so?
Who was awarded the 'Jeevan Raksha Padak' by the Hon'ble President of India?
What is the minimum contribution amount required to open and maintain an NPS Vatsalya account?
Which of the following statements is/are correct with respect to the projections made by the Fitch Ratings-
I.The Indian economy has the potentia...
Which of the following was NOT one of the three initiatives celebrated by MoHUA on its 9th anniversary?
Consider the following statements regarding the "Fortune Global-500".
I. American company walmart secured 1st position in the list.
II. Th...
“Herath” is a festival related to?
__________ and Liberty Global, a London-based telecom firm, signed a €1.5 billion (about $1.64 billion) deal for five years to evolve and scale up the...
What is India’s average annual income in Purchasing Power Parity (PPP) terms as per the latest World Inequality Report?