c++ computer programing Question C3 (a) Describe the difference in the meaning o
ID: 3773444 • Letter: C
Question
c++ computer programing
Explanation / Answer
(a) 1. Difference in the meaning of int a[5]; and a[4];
Here the the statement int a[5] means a is an array of 5 integers and a[4] is only an array declaration without any datatype i.e a[4] means a is an array of size 5
Like a regular variable, an array must be declared before it is used. A typical declaration for an array in C++ is:
type name [elements];
2. 5 means length, 4 means the 5th spot in the array
The elements field within square brackets [], representing the number of elements in the array, must be aconstant expression, since arrays are blocks of static memory whose size must be determined at compile time, before the program runs.
(b) array declaration
double score[5];
1. The array name is score
2. The base type is double
3. The declared size of the array is 5
4. The range of values an index accessing this array can have range: 0 - 4
5. one of the indexed variable or elements of this array is score[3];
(c)
1. Error, the size of the array is 4 but there are 5 elements inputed,The number of values between braces {} shall not be greater than the number of elements in the array
2. No error,When an initialization of values is provided for an array, C++ allows the possibility of leaving the square brackets empty[]. In this case, the compiler will assume automatically a size for the array that matches the number of values included between the braces {}:
3. should be int x[4], not int x[SIZE]
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.