// This tut contains Arrays and Pointers Arithmetic in C++
#include<iostream>;
using namespace std;
int main(){
int marks[]={23,45,86,98};
cout<<"The value of marks[0] is : "<<marks[0]<<endl;
cout<<"The value of marks[1] is : "<<marks[1]<<endl;
cout<<"The value of marks[2] is : "<<marks[2]<<endl;
cout<<"The value of marks[3] is : "<<marks[3]<<endl;
marks[1]=82;
marks[0]=75;
cout<<"marks : "<<marks<<endl; // If we print marks array then it will return address of array.
cout<<"marks[0]: "<<marks[0]<<endl;
cout<<"marks[1]: "<<marks[1]<<endl;
//Accessing elements in array using loop
cout<<"This is mathmarks"<<endl;
int mathmarks[]={81,89,92,98};
for (int i = 0; i < 4; i++)
{
cout<<"The value of mathmark["<<i<<"] is : "<<mathmarks[i]<<endl;
}
cout<<"mathmarks :"<<mathmarks<<endl;
//Pointers and arrays
int* p=mathmarks;
cout<<*(p++)<<endl;
cout<<*(++p)<<endl;
cout<<"The value of *p is :"<<*(p)<<endl;
cout<<"The value of *(p+1) is :"<<*(p+1)<<endl;
cout<<"The value of *(p+2) is :"<<*(p+2)<<endl;
cout<<"The value of *(p+3) is :"<<*(p+3)<<endl;
return 0;
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.