4,659 views

8 Answers

Best answer
24 24 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 1 vote

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:
Position:
Show:

Related questions

3 3 votes
4 answers 4 answers
1.6k
1.6k views
Arjun asked Oct 18, 2016
1,629 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 2 votes
5 answers 5 answers
3.1k
3.1k views
Arjun asked Oct 18, 2016
3,128 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; }
13 13 votes
1 answers 1 answer
3.6k
3.6k views
Arjun asked Oct 18, 2016
3,552 views
#include <stdio.h int foo(int a[100]) { return sizeof(a); } int main() { int a[10]; printf("%d", foo(a)); }What will be the output of the above code ignoring any compiler...
4 4 votes
2 answers 2 answers
2.4k
2.4k views
Arjun asked Oct 18, 2016
2,391 views
No. of times '*' will be printed by the following C code is _____#include<stdio.h void foo(int x) { switch(x){ case 1: printf("*"); case 2: printf("*"); case 3: printf("*...