Lab Activity - 3
From WikiEducator
Lab Activity (proceed sequentially) :
Part a ) : Execute the following code and note down the error if obtained otherwise note down the output
main( )
{
clrscr();
int arr[5] = {12 , 14 , 16 , 18} ;
for(int i = 0 ; i <= 4 ; i++)
{
cout<< arr[i];
arr++;
}
getch( );
} // end of main( )
Part b) : Execute the following code and note down the error if obtained otherwise note the
main( )
{
clrscr( );
int *arr = new int[5];
for(int i = 0 ; i <= 4 ; i++)
{
cout<< “Enter a value :” ;
cin>> *(arr + i) ;
}
for(i = 0 ; i <= 4 ; i++)
{
cout<< *arr;
arr++;
}
getch();
}
Part c) : What have you observed in Part a) and Part b) ? What inferences you draw from there outcomes. Note down all the inferences you approached.
Part d) : Now execute the following code and note down the error or output whatever you get:
main( )
{
clrscr( );
const int *arr = new int[5];
for(int i = 0 ; i <= 4 ; i++)
{
cout<< “Enter a value :” ;
cin>> *(arr + i) ;
}
for(i = 0 ; i <= 4 ; i++)
{
cout<< *arr;
arr++;
}
getch();
}
Part e): Compare the result of Part a) and Part e). Write the inferences that you have drawn from this comparison in your notebook and show it to your teacher
| By performing the activity given above you would find that all arrays declared in C++ are nothing but a const pointer having the address of the first element of the same array. |
click the link below to post your comment , response , reflections to the above question
http://wikieducator.org/Talk:Lab_Activity_-_3