Why sizeof is an operator and strlen is a function?
Printable View
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....:cool:
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
[QUOTE=sat_yucky;11306]strlen is a function only because it always returns a value.......
Sizeof on the other hand never returns any value..... thus an operator....:cool:[/QUOTE]
So you mean to say that if a function doesnt return anything then its an opearator rather than a function ?
In that case all void functions are operators ...
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. :eek:
I strongly agree with “mef526” :D
[QUOTE=sutnarcha;13065]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. :eek:
I strongly agree with “mef526” :D[/QUOTE]
Yes , even i agree over that .. ;) ..
“mef526” is correct. sizeof() is done at compile time and strlen() is done at runtime. :) and that is the only reason why ANSI C++ treats strlen() as function and sizeof() as operator.