Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ computer programing Question C3 (a) Describe the difference in the meaning o

ID: 3773444 • Letter: C

Question



c++ computer programing

Question C3 (a) Describe the difference in the meaning of int a [5]: and the 2 marks) 6) Describe the meaning of a [ 4 ] . (ii) What is the meaning of the [5] and [4] in each case? (2 marks) (b) In the array declaration (5 marks) double score[51 identify the following: (i) The array name (ii) The base type (ii) The declared size of the array (iv) The range of values an index accessing this array can have (v) One of the indexed variables (or elements) of this array Identify any errors in the following array declarations: (i) int x[4] = { 8, 7, 6, 4, 3 }; (ii) int x[] = { 8, 7, 6, 4 }; ili) const int sIZE 4: (c) (6 marks) int x [SIZE]

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]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote