Array is a best way of storing the same type of data in consecutive memory location. In this tutorial we learn how we declare and Initialize an array in c/c++ language.
In C/C++ we are used two type of array:
1- One-dimensional arrays
2- Multidimensional arrays (will be discussed in next Tutorial)
If we want to store the marks of 10 student the there is no need to declare the separate variable for each student marks. W can declare an array of 10 student.
For example:
#include #include void main(void) { int marks[5]; marks[0]=78; marks[1]=99; marks[2]=59; marks[3]=67; marks[4]=78; marks[5]=67; marks[6]=87; marks[7]=56; marks[8]=88; marks[9]=68; }
We can also use for loop for input and output purpose.
For example
#include #include #include void main(void) { int marks[10]; for(i=0;i<=9;i++) { cin>>marks[i]; // this statement will get the marks[0], marks[1] and up to son for i=0 to 9. } for(i=0;i<=9;i++) { cout<<"marks[i]; // this statement will display the marks[0], marks[1] and up to son for i=0 to 9. } getch( ) ; }
Note :- Important thing to remember when working with arrays in C/C++ language suppose you declared an array of 10 elements. Let's say, int testArray[10]; You can use the array members from testArray[0] to testArray[9].
Declaring and Initializing Local Variable in C
Declaring and Initializing Global Variable in C Language
Printf Function In C Language
Sacnf Function In C Language
for Loop in C Language
While Loop in C Language
Do While Loop in C Language
Switch Case Statement IN C
IF -Else Statement IN C
Break Statement IN C /C++
User Define Function IN C /C++
Cout/Cin Function IN C /C++
Array IN C /C++
Two Dimensional Array IN C /C++
String In IN C /C++
Pointer In IN C /C++
Const and volatile keyword IN C /C++
Class and Object in C++
Function Over Loading in C++
Character Array In C++
Constructor in C++
Operator overloading in C++
Function Templates in C++
ATM Sample Project In Simple C Language
Find Area of Shape Using Function In C++