Arrays & Strings C++ Arrays An array is a one of the data structure in C++, that can store a fixed size sequential collection of elements of same data type. Define an Array in C++ Syntax: type arrayName [ arraySize ]; An array type can be any valid C++ data types, and array size must be an integer constant greater than zero. Example: double salary [ 15000 ]; Initialize an Array in C++ Arrays can be initialized at declaration time: int age [ 5 ]={ 22 , 25 , 30 , 32 , 35 }; Initializing each element separately in loop: int newArray [ 5 ]; int n = 0 ; // Initializing elements of array seperately for ( n = 0 ; n < sizeof ( newArray ); n ++) { newArray [ n ] = n ; } A Pictorial Representation of the Array Accessing Array Elements in C++ int newArray [ 10 ]; int n = 0 ; // Initializing elements of array seperately for ( n = 0 ; n < sizeof ( newArray ); n ++) { newArray [ n ] = n ; } int a = newArray [ 5 ]; // Assigning 5th element of array value to integer ...
In this you get all theory part for languages like C,C++,JAVA and Python