menu search
brightness_auto
more_vert

In the case of character array what is the difference b/w strlen() and sizeof() ?

thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike

1 Answer

more_vert
 
verified
Best answer

In character array strlen() returns the number of characters, while sizeof() returns the number of occupied bytes by character array.

Example

#include <stdio.h>
#include <string.h>

int main()
{
	char text[100]= "Sample test";
	printf("%d,%d", strlen(text), sizeof(text));
	return 0;
}

In this example strlen(text) will return 11 because total number of characters are 11 and sizeof(text) will return 100, because text variable will take 100 bytes in memory

thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike

Related questions

thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike
1 answer

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

648 users

...