Is sizeof() a function or operator?

0 Nayab Basha Sayed · May 19, 2015
I thought sizeof() is only considered to be an operator. But this tutorial teaches it's function too.. Could Anybody Explain difference....

Post a Reply


Oldest  Newest  Rating
0 Laura Lee · May 24, 2015
sizeof is a compile time operator. 

The compiler interprets the value for sizeof.
+1 Michael Bradford · May 20, 2015
If you have learned about Operator overloading you'll know that operators are just essentially short-hand version of functions, like the "+" operator just takes the two things on its left and right as arguments and adds them together, so in a way operators are functions. If you haven't learned about Operator overloading yet.. well now you have a basic idea.

Also yeah if your using sizeof(x) it's more accurate to call that a function than an operator, an operator would something like the "+" in a + b, the "=" in a = b, or the ">" in sizeof(a) > sizeof(b); but again remember all of those operators are essentially shortcuts for functions that do something to the things on both sides of them as arguments, +(int left, int right) { return left + right; } to give you a psuedo-code example.
0 Sengngy Kouch · May 19, 2015
@Nayab: Hi there, as long as you see the parentheses () they are a function.

Example of function: 

void doSomething();

void doSomething (int num);

void doSomething (double num);

  • 1



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator