- 1

Вопрос о массиве из, к примеру, 7 значений.

если 5 из них объявить, а вызвать шестой, то он будет равен 0, а если вызвать седьмой, то это будет случайное число... почему?

28th Mar 2017, 7:11 AM
Роман Кузнецов
Роман Кузнецов - avatar
12 ответов
+ 10
#include <iostream> using namespace std; int main(){ int a[5] = {1,2,3,4}; cout << a[4] << endl;//0 int b[2] = {1,2}; cout << b[3];//will be some random number . Ah ha as I said [7] is unsigned value. *REPEAT at unsigned value*. so It generate random mumber }
28th Mar 2017, 8:23 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 9
If I guess [7] is the unassigned value and seed (random seed number in random lesson of sololearn) is unassigned variable type too I mean seed is unassigned value I think that's the reason Please be in english :( I'm confused
28th Mar 2017, 7:41 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 9
Ha ha I try it,ya That stuff can create random more faster in c++ *Record this trick*
28th Mar 2017, 7:43 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 9
Nvm My english is worse than you
28th Mar 2017, 7:44 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 8
Mmm.... Where is my random source file....? Phewww That file can explain to you uh lot
28th Mar 2017, 7:55 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 6
random number??? what???
28th Mar 2017, 7:35 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
0
случайное, но постоянно одно и тоже
28th Mar 2017, 7:39 AM
Роман Кузнецов
Роман Кузнецов - avatar
0
попробуйте сами
28th Mar 2017, 7:40 AM
Роман Кузнецов
Роман Кузнецов - avatar
0
sorry)
28th Mar 2017, 7:43 AM
Роман Кузнецов
Роман Кузнецов - avatar
0
my eng very bad
28th Mar 2017, 7:43 AM
Роман Кузнецов
Роман Кузнецов - avatar
0
#include <iostream> using namespace std; int main() { int b[7] = {11, 45, 62, 70, 88}; cout << b[0] << endl; // Outputs 11 cout<< b[3] << endl; // Outputs 70 cout<< b[6] << endl; // Outputs 0 cout<< b[7] << endl; // Outputs Random return 0; }
28th Mar 2017, 7:52 AM
Роман Кузнецов
Роман Кузнецов - avatar
- 1
but number 7 , how in space, i dont wrote she's in code
28th Mar 2017, 7:57 AM
Роман Кузнецов
Роман Кузнецов - avatar