?
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.
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.
Join the Discussion
Login to post a comment or share your explanation.
LoginYou 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.
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.
You cannot apply sizeof to void directly in standard C.
Doing so will typically result in a compiler error, like: