+1 vote
106 views
in C program by (3.4k points)
edited

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

1 Answer

0 votes
by (3.4k points)
selected by
 
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

Related questions

+1 vote
1 answer 124 views
+1 vote
1 answer 148 views
0 votes
1 answer 180 views
0 votes
1 answer 108 views
asked May 14, 2022 in C program by Doubtly (98.9k points)
0 votes
1 answer 134 views
asked May 15, 2022 in C program by Doubtly (98.9k points)
+1 vote
1 answer 195 views

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

554 users

...