• C

Can argument of sizeof operator have an expression?

Can I do following:

sizeof ( int * 3)


Thanks!
LVL 1
naseeamAsked:
Who is Participating?
 
Infinity08Connect With a Mentor Commented:
That wouldn't make sense, because you're trying to multiply a type with a value.

Maybe you meant :

        sizeof(int) * 3

?
0
 
naseeamAuthor Commented:
You are correct!   I appreciate that!
0
 
naseeamAuthor Commented:
Very fast response.  Exactly what I needed.
0
 
evilrixSenior Software Engineer (Avast)Commented:
Although something like this should work...

sizeof ( 3 * 6 );

...since the result of 3 * 6 (both of implicit type int) is of type int thus the sizeof will return the size of the result type, which is an int.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.