1,776 views

7 Answers

0 votes
0 votes

"Hello" is saved as "Hello\0", "\0" being the NULL terminator.

strlen() is used to get the length of an array of chars / string. 

strlen() takes a pointer to a character, and walks the memory from this character on, looking for a NULL character. It counts the number of characters before it finds the NULL character.

=5

sizeof() is used to get the actual size of any type of data in bytes.

Hence it would include the NULL terminator as well.

=6.


if(sizeof(string) <= strlen(string))

if-condition fails, so print 0.

Answer:

Related questions

3 votes
3 votes
4 answers
1
Arjun asked Oct 18, 2016
780 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,577 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