ExamVeda
Login
Home
Operators and Expressions
?

Which of the following cannot be used inside sizeof?

Answer & Solution
Correct Answer: Option B
sizeof is a compile-time operator in C that determines the size, in bytes, of a variable or data type.

Option A: pointers – Valid. sizeof can be used with pointers to determine the size of the pointer type.

Option B: functions – Invalid. You cannot use sizeof on functions because functions do not have a defined size at compile time. sizeof requires a complete type, and functions are not complete objects in C.

Option C: macro definition – Valid. If the macro expands to a valid expression or type, sizeof can be used on it.

Option D: none of the mentioned – Incorrect because functions cannot be used with sizeof.

Therefore, the correct answer is Option B: functions.
Examveda
Question posted by Examveda
Community

Join the Discussion

3 Comments
Onkareshwar Datt
Onkareshwar Datt 1 year ago
❌ Not allowed directly
You cannot use sizeof(function_name) because a function doesn't have a size in C.
However, you can use sizeof(&function_name), because that gives you a function pointer, which does have a size.

So sizeof(main) is invalid, but sizeof(&main) is valid.
Onkareshwar Datt
Onkareshwar Datt 1 year ago
❌ Not allowed directly
You cannot use sizeof(function_name) because a function doesn't have a size in C.
However, you can use sizeof(&function_name), because that gives you a function pointer, which does have a size.

So sizeof(main) is invalid, but sizeof(&main) is valid.
Onkareshwar Datt
Onkareshwar Datt 1 year ago
The void type means no type—it's an incomplete type, meaning it cannot have a size.

You cannot apply sizeof to void directly in standard C.

Doing so will typically result in a compiler error, like: