0
#include <iostream>
using namespace std;

struct td{
    int ** subj_no;
};


int main(){
    td p;
    **p.subj_no = new int * [7];
}

If not then how should I accomplish this task? What's the corrected version?

Edited by MRehanQadri

2
Contributors
1
Reply
12
Views
4 Years
Discussion Span
Last Post by vmanes
1

Close but not quite.

What sort of structure are you intending to create? If it's a two dimensional array, you first allocate the pointers to the rows, then allocate the rows, like:

int main(){
    td p;
    int i;
    p.subj_no = new int * [7];

    for( i = 0; i < 7; i++ )
        p.subj_no[i] = new int [10]; //now we have 7 rows of 10 items

}

You could write a constructor method for your struct. Keep in mind that in C++ the only difference between a struct and a class is the default visibility.

Edited by vmanes

Votes + Comments
Thanks!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.