Im trying to learn dynamic arrays in C++. For integer, dynamic arrays are like that:
int main()
{
int x;
cin >> x;
int *dynamic = new int[x];
//some codes
delete [] dynamic;
return 0;
}
How can i create dynamic struct array? I tried this code and i failed.
struct Phone{
char name[30];
char number[20];
}
int main(){
int x;
cin >> x;
Phone *record;
Phone *record = new Phone[x];// Code fails here
}
Im so confused in dynamic arrays. Please help me. Thanks.
recorddeclarations is necessary (or allowed) just because the type changed?