Course Content
C++ Introduction
C++ Introduction
Working with the Array
Reminder how to access an array by index
main
#include <iostream> int main() { int myArray[3] = { 67, 23, 87 }; std::cout << myArray[0] << std::endl; std::cout << myArray[1] << std::endl; std::cout << myArray[2] << std::endl; }
Note
Index counting starts from zero, making the first element in a list or array the zeroth element.
Swipe to show code editor
- Declare a string array with a size of 5;
- Initialize the array with the following values:
- First element: "!";
- Second element: "World";
- Third element: ",";
- Fourth element: "Hello";
- Fifth element: " ".
- Construct the message by arranging the elements of the array in the correct order ("Hello, world!")and then set it to the value of the message variable;
- Output the constructed message.
Thanks for your feedback!
Working with the Array
Reminder how to access an array by index
main
#include <iostream> int main() { int myArray[3] = { 67, 23, 87 }; std::cout << myArray[0] << std::endl; std::cout << myArray[1] << std::endl; std::cout << myArray[2] << std::endl; }
Note
Index counting starts from zero, making the first element in a list or array the zeroth element.
Swipe to show code editor
- Declare a string array with a size of 5;
- Initialize the array with the following values:
- First element: "!";
- Second element: "World";
- Third element: ",";
- Fourth element: "Hello";
- Fifth element: " ".
- Construct the message by arranging the elements of the array in the correct order ("Hello, world!")and then set it to the value of the message variable;
- Output the constructed message.
Thanks for your feedback!