New course! Every coder should learn Generative AI!
Try a free lesson+ 2
What is the output of this code???
Why this code generate the following output ...Code is... int a[100]; int main () { cout <<a [99]; } ...Options... 1 0 Unpredicted Error ...Output... 0
5 Answers
+ 3
It will be 0 because the variable has global scope. Only for objects with automatic storage duration / local scope the value would be indeterminate.
int global_arr[100]; // uninitialized, will be 100 x 0
int main() {
int local_arr[100]; // uninitialized, will be 100 x indeterminate
return 0;
}
+ 6
Because of array is not initialized, it will return some random value from memory. So, unpredicted is the right response
+ 5
Depending if memory was cleared or not by other previous program it could be zero or other value
+ 3
since its not initialized, the content of a mostly filled with garbage value. it could be 0 or any other number
+ 1
Javier Felipe Toribio but the output is 0 why?