in Programming in C retagged by
419 views
1 vote
1 vote
char st[] = {‘G’,’A’,’T’,’E’,’\0’};

then string ka length 4 hoga ya 5 with null character?
in Programming in C retagged by
419 views

1 comment

you are asking what will be output if we pass it to sizeof() operator?

coz i believe sizeof() does count \0 null character. so it will return $5$
0
0

2 Answers

4 votes
4 votes
Best answer

If you use length() method, then it would return 4. But if you use sizeof() method, then it would return 4+1(for null character)=5.

 

edited by
0 votes
0 votes

The strlen() function calculates the length of the string by counting the number of all characters until it reaches the null terminator ('\0'). So the length of this string “GATE” is 4.

Related questions