Let us consider int array[] = {2,33,4,56,7,8}; //case A
if sizeof() checked '\0' as end of char[] array! what does sizeof(array) check as a sentinel value to find end of int array, therefore size of array in case A?
If I were to implement sizeof (intArray) , there is no liberty to access of sentinel value information ?
sizeof
does not check anything. It only looks like a function call, but it is really an operator, a compiler trick to insert the size as known to the compiler at compile time.
Here is how sizeof
interacts with C arrays: when you declare an array, you specify its size as a constant, as a run-time integer expression, or implicitly by supplying a certain number of values to put into your array.
When the number of elements is known at compile time, the compiler replaces sizeof(array)
with the actual number. When the number of elements does not become known until runtime, the compiler prepares a special implementation-specific storage location, and stores the size there. The running program will need this information for stack clean-up. The compiler also makes this hidden information known to the runtime portion of sizeof
implementation to return a correct value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With