In this post, we will learn about what is an array? and declaration of arrays.
What is an Array?
An array can be defined as a collection of data, but the data type of all the elements should be the same i.e., all the elements should be of integer type or all be of character type, etc but not the mixture of data types like two elements are integer and other are characters.
Declaration of an Array:
The syntax of the array declaration in C++ is as follows:
dataType_name_[size]={elements separated by commas};
for example:
1. int A[5]={1,2,3,4,5};
This means that I have declared an array of data type int and of size 5 having elements 1,2,3,4,5.
2.char B[3]={'A','B','C'};
This means that I have declared an array of data type character of size 3 having A, B, and C as elements.
In character array, you have to keep the elements in single quotes.

Comments
Post a Comment