One thing that's different in C++ is how you declare arrays. You probably remember that this is how it's done in Pascal: somearray : array[1..10] of integer; C++ makes it easier to create arrays - to create the same array as shown above, you simply say: int somearray[10]; Wasn't that easy? One big difference is that, unlike Pascal, C++ requires that all of your arrays start at 0. So, if we wanted to access element 5 of our array, we'd say: somearray[4];
Confused? Remember that we're starting the array at 0. The first element is
" That may feel kind of silly, but hopefully what we're about to say will make up for it. In C++, variables can be declared nearly anywhere inside a program! What does this mean? Well, consider this code: void main(void) / In Pascal: "procedure main;" { / In Pascal: "begin" int a; / In Pascal: " a: integer;" int b; / In Pascal: " b: integer;" } / In Pascal: "end"
The variables are being declared right in the middle of a program! That's right
-- you can say " |