Here we do not give array size. So how memory (20 bytes) allocated for arr?Code:int main() { int arr[] = {1, 2, 3, 4, 5}; }
By counting the numbers between comma(,) operators inside the curly braces?
Here we do not give array size. So how memory (20 bytes) allocated for arr?Code:int main() { int arr[] = {1, 2, 3, 4, 5}; }
By counting the numbers between comma(,) operators inside the curly braces?
Yes, the compiler counts the initialisers, and allocates the array size based on that count.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.