critically explain why you would consider arrays over normal data
types AP[5 marks]
b. from your explanation in “a” above, define and initialize an array called
BongoBar of type string and having 4 elements. CR[5 marks]
c. embed your array in “b” above in a full c++ program and display each
of the initialized data when your program executes. CR [5 marks]
d. critically explain what will happen if an amateur programmer decides to
called BongoBar[5] in the main function in your program in “c” above.
(a) The question is not clear, the answer to it depends on its context.
// (b)
std::string BongoBar[4] = {"Bon", "Go", "Bar", "4"};
// (c)
#include <iostream>
using namespace std;
int main() {
std::string BongoBar[4] = {"Bon", "Go", "Bar", "4"};
for (int i = 0; i < BongoBar.length; i++) {
std::cout << BongoBar[i] << std::endl;
}
return 0;
}
(d) It will just output all the elements of this array.
Comments
Leave a comment