Arrays in C++
An array is a data structure that allows us to store a fixed number of elements of the same data type in contiguous memory locations.
Syntax to Declare an Array
dataType arrayName[arraySize];
Example
C++
#include <iostream> #include <string> using namespace std; int main() { // Declare and initialize an array of strings string fruits[] = { "Apple" , "Banana" , "Orange" , "Grapes" }; // Access and print each element of the array for ( int i = 0; i < 4; i++) { cout << "Fruit at index " << i << ": " << fruits[i] << endl; } return 0; } |
Output
Fruit at index 0: Apple Fruit at index 1: Banana Fruit at index 2: Orange Fruit at index 3: Grapes
C++ Cheatsheet
This is a C++ programming cheat sheet. It is useful for beginners and intermediates looking to learn or revise the concepts of C++ programming. While learning a new language, it feels annoying to switch pages and find different websites for different concepts that are easily understandable. You can learn C++ concepts very easily using this cheat sheet.
C++ is a high-level programming language. It was developed in 1983 by Bjarne Stroustrup at Bell Labs. It is used for developing various applications.
Contact Us