Skip to content
doubtly

1 answer

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

Mr C. · 18 Jun 2022 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.