C Programming · Question 17 · Easy

What will be the output of the following C program?

#include <stdio.h>
#include <string.h>

int main(void) {
    char city[] = "Delhi";
    printf("%d %d", (int)sizeof(city), (int)strlen(city));
    return 0;
}
  1. 5 5
  2. 5 6
  3. 8 5
  4. 6 5
Answer and explanation

Answer: D. 6 5

Explanation: sizeof counts the whole array, including the terminating '\0', so it is 6. strlen counts characters before '\0', so it is 5.

Previous: What will be the output of the following C program? · Next: What will be the output of the following C program?

Practise c programming

Try a fresh set of c programming questions with an explanation after every answer, free and without signing up: C Programming practice. Or sit a full placement mock test.

More c programming questions

More technical & programming practice

Java · Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge