Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C: sizeof(), sizeof () and sizeof [closed]

Tags:

c

sizeof

I have read a post on C before here on SO. I have forgotten what it was about, but definitely was not about what I would like to ask here - sizeof.

It was argued between 2 answerers in the comment section. It was a heated debate between the two but an explanation was never explicitly uttered.

I have tried to find it for two days, but I have not been able to locate it, hence my question here. And Googling didn't generate any result regarding this.

Focus: sizeof() or sizeof () or just sizeof

So there are basically 2 types of these people regarding this:

First group:

A scholar who swears by the name of Ritchie and never will drive a car because he tries to register his license plate with:

sizeof () with a space between sizeof and () and the government (in some countries this - () - is allowed in license plates) won’t allow the empty space between numbers/letters.

Second group:

Every once in a while a decorated C veteran with a tie-dyed shirt who would reply you like so when asked: „I really don’t know man, what’s the difference? I don’t even know what the deal is. I don't even remember.. Those Ivy Lea…. sizeof(), sizeof () or just sizeof, me no worry, man. “

So, should sizeof be written with a space between sizeof and its () or even without the () or really it doesn’t matter?

I welcome explanations from C experts and scholars. Those who don’t quite fit into the aforementioned types - the self-taught C Bobs and Marys - with „C99 and Ritchie“ tattooed on his/her arm are also welcomed.

It doesn’t hurt me either ways but I am just curious whether or not if it is a „standard“ to put a space between sizeof and () or even one without ().

Or are they really all the same - would be interesting to me.

like image 939
Unheilig Avatar asked Jan 21 '26 09:01

Unheilig


2 Answers

All yield the same result and which you use is entirely down to preference.

Note that you must use parens if you are supplying a type name. More detail on that can be found here: What does sizeof without () do?

like image 162
David Heffernan Avatar answered Jan 25 '26 23:01

David Heffernan


No difference in sizeof() and sizeof (). But there is a little difference in sizeof and sizeof (). The standard says about it:

6.5.3 Unary operators:

sizeof unary-expression
sizeof ( type-name )   

If the operand is type name, then () is needed. Otherwise, for unary-expressions you can use it without ().

like image 45
haccks Avatar answered Jan 26 '26 00:01

haccks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!