wrong cout of array

Please, what is wrong now?
I am even checking in a book...???

1
2
3
4
5
6
7
8
9
10
  #include<iostream>
using namespace std;


int main(){

int array[3]={ 33, 55, 77 };
cout<<array[3];
return 0;
}


Many thanks!
Counting starts from zero, not from one.

This means that array has elements array[0], array[1] and array[2].

The above means that array[3] does not exist.

And I will remind you this: start to use an indent style, and make your code easier to read.
For example, Allman style:

1
2
3
4
5
6
7
8
9
10
#include<iostream>
using namespace std;

int main()
{
    int array[3] = {33, 55, 77};

    cout << array[3];
    return 0;
}


http://en.wikipedia.org/wiki/Indent_style

I'm keeping an eye on you. It seems you are ignoring people's advice on a regular basis, and post bogus questions.
Hello!
I did not put the question correctly!


I ment, how to print the WHOLE ARRAY???
array[3]={33,44,55}

then array[1]=33
array[2]=44
array[3]=55

it means, we can ONLY print elements, not the whole array, do we, or??

Many thanks!

p.s. I am just starting, I sometimes literarily do not manage write indentation well cause I am short with time and still have n practise to do it automathically!!!
it means, we can ONLY print elements, not the whole array, do we, or??

In C++ you cannot simply print an entire array like that.
(In other languages you can but that doesn't matter.)

You could to use a for() loop to print the contents.

1
2
for (int i=0; i < length_of_array; ++i)
    cout << array[i] << ' ';


array[3]={33,44,55}

then array[1]=33
array[2]=44
array[3]=55

As I already said, counting starts from zero, not from one.

array[0]=33
array[1]=44
array[2]=55


Ok, got it, the SAME example is in the book, I just wondered if i could be done ...shorter, but it is ok!

Thanks!
Don't forget the one exception though catfish; an array of characters.

1
2
char array[6] = "hello";
cout << array << endl;

Thanks:)!
Topic archived. No new replies allowed.