+ 2
Arrays
please I need more explanation about this code I could not understand it please someone should help me #include <iostream> using namespace std; int billy[]={16,2,77,40,12071}; int n,result=0; int main() { for (n=0;n<5;n++) { result +=billy[n]; } cout <<result; return 0; }
9 Respuestas
+ 2
In short, that code sum all the elements of a global int array <billy> into variable <result>, which also is defined and initialized on the global space.
Not sure what confused you here, so I'd appreciate it if you can come clearer on the problem.
+ 1
wow thank you @Ipang I just checked it and that's true it's sum all the elements
+ 1
Code Crasher
As per my understanding, something is said to belong in global scope when their declaration/definition is not inside of a function. Here <billy> array is defined outside main function (the only function we see).
You got it right though, the <n> in the for-loop refers to the index of array elements (a range), to be added into <result> variable.
Curiosity is always welcome, no probs 👌
+ 1
Code Crasher
Don't know that much about C/C++ myself, but a lot had said/written something around those languages and electronics or robotics. So I guess it makes just the sense to learn, even if it was just the basics.
Keep crashing bruh 😁
0
No problem buddy 👌
Keep coding and stay safe 👍