1,772 views

7 Answers

Best answer
22 votes
22 votes
char string[] = "Hello"; //'\0' is added by compiler at end of string literals
sizeof(string) = (5+1) = 6  //+1 to store EndOfString char '\0'.
strlen(string) = 5

if(sizeof(string) <= strlen(string)) returns False so it wont print 1 and finally it will print 0.
selected by
1 votes
1 votes

Answer will be Zero as strlen() function always gives the actual length of string excluding '\0', but '\0' is always present at the end of string taking space in memory so it is counted in sizeof operator.

Answer:

Related questions

3 votes
3 votes
4 answers
1
Arjun asked Oct 18, 2016
773 views
What will be the output of the following code?#include <stdio.h int main() { char a = 'A', z = 'Z'; printf("%d", z-a); }
2 votes
2 votes
5 answers
2
Arjun asked Oct 18, 2016
1,571 views
The value returned by the following code is _____int foo() { int a[] = { 10, 20, 30, 40, 50, 60 }; int *p = &a , *q = &a[5] ; return q-p; }
12 votes
12 votes
1 answer
3
3 votes
3 votes
2 answers
4