What are differences between sizeof operator and strlen function?
sizeof is keyword of c which can find size of a string constant including null character but strlen is function which has been defined in a header file named string.h and can find number of characters in a string excluding null character. Most probably it is used to compare the size of string with some conditions.
Example:-
#include<string.h>
void main(){
int a,b;
a=strlen("itorian");
b=sizeof("itorian");
printf("%d %d",a,b);
getch();
}
Example:-
#include<string.h>
void main(){
int a,b;
a=strlen("itorian");
b=sizeof("itorian");
printf("%d %d",a,b);
getch();
}
Comments
Post a Comment