Why sizeof is an operator and strlen is a function?
Why sizeof is an operator and strlen is a function?
strlen function is use to get the string length
while size of is used to get the size of varriable
Hello,
sizeof is called as a operator because it operates means he never sends a parameter .
Whille strlen sends the string mention and returns integer equivalent to the number of char in string.
strlen is a function only because it always returns a value.......
Sizeof on the other hand never returns any value..... thus an operator....
sizeof is done at compile time. strlen is done at runtime.
char ac[100] = "This is a test";
int i = sizeof(ac); // i = 100
int j = strlen(ac); // j = 14
char *pc = ac;
int k = sizeof(pc); // k = 4 (pointer size)
int m = strlen(pc); // m = 14
Hay, it has nothing to do with whether it takes arguments or not or returns any value or not.
Its only coz sizeof() is done at compile time.
I strongly agree with “mef526”
Lack of WILL POWER has caused more failure than
lack of INTELLIGENCE or ABILITY.
-sutnarcha-