What is the output of this code??? | Sololearn: Learn to code for FREE!
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

25th Jun 2019, 9:58 AM
Nouman Bin Sami
Nouman Bin Sami - avatar
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; }
25th Jun 2019, 1:49 PM
Anna
Anna - avatar
+ 6
Because of array is not initialized, it will return some random value from memory. So, unpredicted is the right response
25th Jun 2019, 10:31 AM
Javier Felipe Toribio
Javier Felipe Toribio - avatar
+ 5
Depending if memory was cleared or not by other previous program it could be zero or other value
25th Jun 2019, 12:23 PM
Javier Felipe Toribio
Javier Felipe Toribio - avatar
+ 3
since its not initialized, the content of a mostly filled with garbage value. it could be 0 or any other number
25th Jun 2019, 10:01 AM
Taste
Taste - avatar
+ 1
Javier Felipe Toribio but the output is 0 why?
25th Jun 2019, 11:54 AM
Nouman Bin Sami
Nouman Bin Sami - avatar