0
Strang value
#include <iostream> #include <string.h> using namespace std; int main() { int DB[9]; for(int i=0;i<=10;i++){ DB[i]; cout << i << "----:" << DB[i] <<endl; }[![enter image description here][1]][1] } [1]: https://i.stack.imgur.com/stgNN.png **The values of the a
5 Réponses
+ 4
Ipang sorry actully i have not noticed headerfile it was my mistake thanks for mention this.
+ 4
Ipang 😆😂😂😜
+ 2
Its not strange values actully you created Array DB which type is int type but u have not initialize your array that's why it printing like this. Please set values or use cin if u want to take input from user.And use return 0; becoz u used int main()
By default `main` returns 0, which signifies success (any other value signifies failure).
Instead of 0 you can explicitly use
⋮ return EXIT_SUCCESS;
where `EXIT_SUCCESS` is declared by the header `<stdlib.h>`. It also declares `EXIT_FAILURE`.Unfortunately with a value of 1 in Windows
try this
#include <iostream>
#include <string.h>
using namespace std;
int main() {
int DB[]={1,2,3,4,5,6};
for(int i=0;i<=5;i++){
cout << i << "----:" << DB[i] <<endl;
}
return 0;
}
+ 1
1. For C++ include <string> not <string.h>
2. Array <DB> is not initialized, so it contains 9 elements with garbage values. You can initialize an array as follows ...
int DB[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
3. The for-loop should check counter <i> value being less than 9 rather than 10, because the aray only has 9 elements. That is ...
for(int i = 0; i < 9; i++)
{
cout << i << "----: " << DB[i] << endl;
}
+ 1
♨️♨️
No prob sis, just don't get it why include <string> when string isn't used in his code above 😁