Allocation/Deallocation of array within struct

Okay so I have a question. Lets say I want to create arrays of exact size for abstract data type members. For example:

1
2
3
4
5
6
struct student
{
   char name[10];
   int idNumber;
};


my question is how to declare this array as null so that later i can give it an exact size to match the length of the name. if it were not a part of the struct i would imagine that the code would look something like this:

1
2
3
char * name = NULL;

name = new char[10];


I don't think abstract is the word you're looking for.

1
2
3
4
5
6
7
#include <string>

struct student
{
    std::string name ;
    int idNumber ;
};
String is better for this as cire said.

Although you can also have a pointer in there and dynamically point that array later on to a char array. This will have your struct the size of a pointer and an int.
yeah we are supposed to use c-style strings so therefor i cannot use the string class object. if i just maid it a pointer can i later define it as an array?
1
2
3
4
5
6
struct student
{
   char * name;
   int idNumber;

};


and later in the code do something like this:

 
name = new char[10];
Yes you can do that
Topic archived. No new replies allowed.