6 votes 6 votes What is the output of the code given below? # include<stdio.h> int main() { char name[]="satellites"; int len; int size; len= strlen(name); size = sizeof(name); printf("%d",len*size); return 0; } $100$ $110$ $40$ $44$ Programming in C isro-2020 programming array normal + – Satbir asked Jan 13, 2020 • edited Apr 10, 2020 by go_editor Satbir 3.9k views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
5 votes 5 votes Answer: b) 110. The above char array name can be written as below: char[] name = {'s','a','t','e','l','l','i','t','e','s', '\0' }; strlen gives no of characters in a string without the null in the end = 10. sizeof gives the no of characters(no of bytes specifically) in a string including the null at the end = 11 So 11*10 = 110. Tuhin Dutta answered Jan 13, 2020 • edited Jan 13, 2020 by Tuhin Dutta Tuhin Dutta comment Share Follow See all 0 reply Please log in or register to add a comment.
1 votes 1 votes char[] name = {'s','a','t','e','l','l','i','t','e','s', '\0' }; sizeof=11 (as \0 included and number of bytes) strlen = 10 (as \0 not included) len * size = 10*11 = 110 Vishwajeet Deulkar answered Aug 17, 2020 Vishwajeet Deulkar comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes char[] name = {'s','a','t','e','l','l','i','t','e','s', '\0' }; here size of will give the total size of the array=11 strlen = 10 (as \0 not included) 10*11 = 110 Pratyush Priyam Kuan answered Feb 10, 2020 Pratyush Priyam Kuan comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes strlen() => Length of string excluding null character. sizeof() => No of bytes allocated including those assigned to null character. so len = 10 and size =11 Output is 11. smsubham answered Mar 20, 2020 smsubham comment Share Follow See all 0 reply Please log in or register to add a comment.