I have an integer array and I want to fill it.

int* a=new int[7];

but I want to check at first if the element a is set before or not.

Ex.

a[3]=2;

a[3] has value but all elements in a hasn't have any value until now, How can I know that??

I tried

if(a==NULL) but it doesn't work

Recommended Answers

All 3 Replies

I tried

if(a==NULL) but it doesn't work

Have you tried initializing the array to null pointers? Then that test would work.

int* a=new int[10];
a=NULL;
// how can I check that a[i] doesn't set before

Dude, it's an array. Treat it as such:

for (int i = 0; i < 10; i++)
    a[i] = NULL;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.