Chapter 4

1: How would you declare each of the following?
  1. actors is an array of 30 char.

  2. betsie is an array of 100 short.

  3. chuck is an array of 13 float.

  4. dipsea is an array of 64 long double.

A1:
  1. char actors[30];

  2. short betsie[100];

  3. float chuck[13];

  4. long double dipsea[64];

2: Declare an array of five ints and initialize it to the first five odd positive integers.
A2:
int oddly[5] = {1, 3, 5, 7, 9};
3: Write a statement that assigns the sum of the first and last elements of the array in question 2 to the variable even.
A3:
int even = oddly[0] + oddly[4];
4: Write a statement that displays the value of the second element in the float array ideas.
A4:
cout << ideas[1] << "\n"; // or << endl;
5: Declare an array of char and initialize it to the string ...

Get C++ Primer Plus, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.