Struc@Array Question
Struc@Array Question
Struc@Array Question
For example:
This will output: 3579. The range-based for loop is especially convenient
when iterating over vectors, which are introduced in Chapter 8, and iterating
over containers, which are discussed in Chapter 18. ■
1. Describe the difference in the meaning of int a[5] and the meaning of
a[4]. What is the meaning of the [5] and [4] in each case?
However, to be safe we want our program to test the array and issue a warning
in case it turns out that some elements are out of order. The following code is
supposed to output such a warning, but it contains a bug. What is it?
double a[10];
<Some code to fill the array a goes here.>
7.2 Arrays in Functions 389
9. Write some C++ code that will fill an array a with 20 values of type int read
in from the keyboard. You need not write a full program, just the code to do
this, but do give the declarations for the array and for all variables.
10. Suppose you have the following array declaration in your program:
int your_array[7];
Also, suppose that in your implementation of C++, variables of type int use
2 bytes of memory. When you run your program, how much memory will
this array consume? Suppose that when you run your program, the system
assigns the memory address 1000 to the indexed variable your_array[0].
What will be the address of the indexed variable your_array[3]?
If my_function takes one argument of type int, then the following is legal:
my_function(n);
Since an indexed variable of the array a is also a variable of type int, just like n,
the following is equally legal:
my_function(a[3]);
If the value of i is 3, then the argument is a[3]. On the other hand, if the
value of i is 0, then this call is equivalent to the following:
my_function(a[0]);