Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
can you please tell me why is it possible to have codes like this?
C++
#include <iostream>

using namespace std;

int main()
{
    int arr[4][4];
    int a, b;
    int temp;
    cout << "Enter four numbers: \n";
    for (a=0; a<4; a++)
    {
        cin >> arr[a][a];  > this is what i'm pertaining and why?    
    }


What I have tried:

I just wanted to know why cin >> arr[a][a] is okay to use
Posted
Updated 7-Mar-20 7:25am
v2
Comments
KarstenK 7-Mar-20 13:26pm    
be aware that you only need a one dimensional array. Look at the arr in the debugger window that you only crossfill that array.

Please have a look at Is it possible to have code like this?[^], which oddly seems quite identical to your question.
 
Share this answer
 
Comments
OriginalGriff 7-Mar-20 6:35am    
I'm guessing same homework.
(I'm kinda hoping they both copy what I wrote word-for-word ... but I'm evil like that)
phil.o 7-Mar-20 6:48am    
:D
Quote:
Is it possible to have this in 2 dimensional array?

Yes, it is possible.
Quote:
can you please tell me why is it possible to have codes like this?

Because the language permit it and programmer want it that way which is just legal.

The question you missed: Is it sensible to code that way?
Form the code I see, it is 1D program fitted in a 2D array, there is no reason to do it that way, it complicate things for no reasons.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900