Question discussion

What is the output of the following C program?#include #include int main() { char s[] = "DSSSB"; printf("%d %d", (int)strlen(s), (int)sizeo…

979Medium DSSSB TGT Computer Science 0 replies 2 views
0

What is the output of the following C program?

#include <stdio.h>
#include <string.h>
int main() {
    char s[] = "DSSSB";
    printf("%d %d", (int)strlen(s), (int)sizeof(s));
    return 0;
}
  • A5 5
  • B5 6
  • C6 6
  • D6 5
Correct answer: B

Explanation

strlen counts 5 characters, while sizeof also includes the terminating '\0', giving 6.

Discussion 0

Nobody has replied yet. Start the discussion!