retagged by
439 views
1 votes
1 votes
char st[] = {‘G’,’A’,’T’,’E’,’\0’};

then string ka length 4 hoga ya 5 with null character?
retagged by

2 Answers

Best answer
4 votes
4 votes

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

1 votes
1 votes
0 answers
1
aakash pandey asked Apr 30, 2022
298 views
We use character array to declare string in C. So, if I declare an array likecharacter ch[ ] = {‘a’,’k’,’a’,’/o’};and try printing ch[3] like :printf(“%...
1 votes
1 votes
2 answers
2
1 votes
1 votes
1 answer
3
Pranavpurkar asked Sep 27, 2022
375 views
DOUBT:suppose a memory space of 16B is given and it is asked that what is the maximum length of string it can store.then do we have to consider the space taken by the �...
2 votes
2 votes
0 answers
4
Shaik Masthan asked May 25, 2018
607 views
#include <stdio.h int main () { char *ptr = "\123456789\n"; printf("%s",ptr); }Can anyone explain what happend with escaping character before 1 ?