while compile time ...

A

amit

Hi,

I'm not sure about what I have read. The book I'm reading about C++
says that it is better to initialize an array while compilation.

Does anybody know how to do it?

Thanks,
Amit
 
G

Gernot Frisch

amit said:
Hi,

I'm not sure about what I have read. The book I'm reading about C++
says that it is better to initialize an array while compilation.

Does anybody know how to do it?

int i[100] // compile time:

int *pI = new int[100]; // run time
delete[]pI;

-Gernot
 
K

Karl Heinz Buchegger

amit said:
Hi,

I'm not sure about what I have read. The book I'm reading about C++
says that it is better to initialize an array while compilation.

Does anybody know how to do it?

int MyData[] = { 1, 2, 6, 8, 9 }

This way, you can force the compiler to count the number of intializer
values for you and don't run the risk of forgetting some.

int MyData[5];

MyData[0] = 1;
MyData[1] = 2;
MyData[2] = 6;
MyData[3] = 8;
// oops forgot about MyData[4]. It's value will be
// undefined.
 
R

Rolf Magnus

Gernot said:
I'm not sure about what I have read. The book I'm reading about C++
says that it is better to initialize an array while compilation.

Does anybody know how to do it?

int i[100] // compile time:

int *pI = new int[100]; // run time
delete[]pI;

This has nothing to do with initialization.
 
G

Gernot Frisch

Rolf Magnus said:
Gernot said:
I'm not sure about what I have read. The book I'm reading about
C++
says that it is better to initialize an array while compilation.

Does anybody know how to do it?

int i[100] // compile time:

int *pI = new int[100]; // run time
delete[]pI;

This has nothing to do with initialization.

for(;;)
printf("I will start reading questions before I answer!\n");
 
A

amit

Thank you.


Gernot said:
amit said:
Hi,

I'm not sure about what I have read. The book I'm reading about C++
says that it is better to initialize an array while compilation.

Does anybody know how to do it?

int i[100] // compile time:

int *pI = new int[100]; // run time
delete[]pI;

-Gernot
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,292
Messages
2,571,494
Members
48,171
Latest member
EllaHolmwo

Latest Threads

Top