Talk:c/language/sizeof

As per standard : "If the type of expression is a variable-length array type, expression is evaluated and the size of the array it evaluates to is calculated at run time." Also, "Note that if a has pointer type (such as after array-to-pointer conversion of function parameter type adjustment), this expression would simply divide the number of bytes in a pointer type by the number of bytes in the pointed type."

Here, we have a variable-length array arr, therefore the size expression is evaluated but arr[0] is a null pointer, so during evaluation it should lead to undefined behaviour and output segmentation fault. But its not the case, program runs smoothly with an output of 8 bytes!! Himanshujha199640 (talk) 10:08, 17 August 2017 (PDT)
 * "runs smoothly" is just as valid as "segmentation fault" for a program whose behavior is undefined. FYI, dereferencing a null pointer directly also does not necessarily lead to a segmentation fault - compilers sometimes simply remove such code. --Cubbi (talk) 10:44, 17 August 2017 (PDT)