0 0 votes What is the output of this program? #include <stdio.h> #include <string.h> int main() { char string[] = "Hello"; printf("%lu %lu", sizeof(string), strlen(string)); return 0; } $5 \ 6$ $5 \ 5$ $6 \ 5$ $6 \ 6$ Programming in C tbb-programming-2 programming-in-c output data-structures + – Bikram 767 views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
Best answer 2 2 votes C. 6 5 sizeof() counts the number of characters in the string, including the null character. (It actually tells you how much memory an object takes. Since each charachter in C++ takes one byte, a string takes as much memory as the number of characters in it, including the null character.) https://en.cppreference.com/w/cpp/language/sizeof strlen() computes the number of characters in the string, ignoring the null character. https://en.cppreference.com/w/cpp/string/byte/strlen sizeof("Hello") = 6. strlen("Hello") = 5. https://ideone.com/oi9ANE Satyajeet Singh answered Jan 11, 2018 • edited Feb 9, 2019 by Pragy Agarwal Satyajeet Singh comment Share Follow See all 3 Comments 3 3 Comments reply sandeep singh gaur commented Feb 8, 2019 reply Follow flag i am confused with strlen() here mentioned strlen compute the number of character in the string ignoring the null character .but i saw a question on go( programming in c:gate 2004-23) where null character is also included to count the lenth of string. 0 0 replyShare sandeep singh gaur commented Feb 8, 2019 reply Follow flag https://gateoverflow.in/?qa=blob&qa_blobid=15045614339529561886 please see this question. 0 0 replyShare ghostman23111 commented Apr 9, 2020 reply Follow flag strlen() will return length as 6 and p[0]=s[6-0] will print nothing. 0 0 replyShare Please log in or register to add a comment.