What is the output of the code given below? C#include <stdio.h> int main( ) {…
2020
What is the output of the code given below?
C#include <stdio.h>
int main( )
{
char name[ ]=“satellites”;
int len;
int size;
len = strlen(name);
size = sizeof(name);
printf(“%d”, len * size);
return 0;
}
- A.
100
- B.
110
- C.
40
- D.
44
Attempted by 887 students.
Show answer & explanation
Correct answer: B
The code calculates the product of strlen(name) and sizeof(name). The string literal 'satellites' consists of 10 characters, so the length variable len is assigned the value 10. The array size includes the null terminator, making sizeof(name) equal to 11 bytes in memory. Consequently, the output is calculated as 10 multiplied by 11, which equals 110.