Pointeri

Intrebari despre limbajul C++, standardul C++, STL, OOP in C++ sau alte subiecte nelegate de VisualC++
Post Reply
david_stelian
Junior
Junior
Posts: 20
Joined: 13 Sep 2014, 22:35
Judet: Dolj

Pointeri

Post by david_stelian » 20 Apr 2016, 00:32

Va salut!

int (*p)[3] este pointer catre un tablou unidimensional de 3 intregi.

Se poate declara un pointer catre un tablou bidimensional de 6 intregi(int tab[2][3])

este ok urmatoarea declaratie ?

int tab[2][3];
int (*q)[2][3];
q = &tab;

Am incercat un cod cu declaratiile de mai sus si codul ruleaza.

Code: Select all

#include <iostream>
#define ROWS 2
#define COLS 3
using namespace std;

int main()
{
    int arr[ROWS][COLS] = {  {11, 12, 13},
                             {21, 22, 23}  };
    int (*p)[ROWS][COLS];
    cout << endl;
    p = &arr;
    for (int i=0; i<ROWS; i++)
    {
        for (int j=0; j<COLS; j++)
            cout << "\t " << (*p)[i][j] << "  ";
		// cout << "\t " << *(*(*p)+i)+j) << "  ";
        cout << endl;
    }
    return 0;
}



Post Reply