0 votes 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 + – Bikram asked May 14, 2017 • edited Aug 14, 2019 by go_editor Bikram 340 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
Best answer 1 votes 1 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 See all 3 3 Comments reply sandeep singh gaur commented Feb 8, 2019 reply Follow Share 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 votes 0 votes sandeep singh gaur commented Feb 8, 2019 reply Follow Share https://gateoverflow.in/?qa=blob&qa_blobid=15045614339529561886 please see this question. 0 votes 0 votes ghostman23111 commented Apr 9, 2020 reply Follow Share strlen() will return length as 6 and p[0]=s[6-0] will print nothing. 0 votes 0 votes Please log in or register to add a comment.