I have a very simple program here that prints out the values contained within the array. My text book uses this within a function, so I tried building a simple main function that calls show_the_world, and it should print 1-5 onto the screen. It also talks about setting your array base to a constant type, as to prevent error, and for ease of editing for later use. I just want to get this working for my own understanding, but clearly I am mixing something up. I tried setting size_of_array as a global constant, but obviously that's wrong. Anything to point me in the right direction will be of great assistance.
I'm not sure I follow. What do you mean by "a[i] is not allowed to change?" And I didn't realize I had to have the indexes declared as constants too. It almost seems a little inconvenient to have a[]={1,2,3,4,5}, when I thought we could have something like a[size_of_array], where I could change the size whenever I need? Or will that just print garbage?
like code int a[size_of_array]; // you should use const number in the [], so please write "#define size_of_array 5" before int a[size_of_array];
And int a[]={1,2,3,4,5}; is right. Complie will count size with first declared and assigned.
The last "void show_the_world(const int a[], int size_of_a);" , you declared const int a[], this arrary a is const, so you can not change a[], any element in a[].