English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

//both are c++ codes try to initialize an array freqs[11] to zeros
//for futur arithmetic calculation
int freqs[11]={0,0,0,0,0,0,0,0,0,0,0};//way 1

//or
int freqs[11];
for(int i=0;i<=10;i++){
freqs[i]=0;
}//way 2
//yes i agree way 2 is much much easier but a loop needs more time to process than direct manipulation

2006-11-16 23:13:51 · 6 answers · asked by Rami 5 in Computers & Internet Programming & Design

6 answers

i agree with krish. just set element 1 (freqs[0]) to 0. but if for some reason you NEED all set to 0, then it would depend on the size of the array. for a small array i would use the first method, but for one with hundreds of elements, i would use the second!

2006-11-17 01:27:51 · answer #1 · answered by justme 7 · 1 0

The loop should be used if the array is larger than you can 'manually initialize'.

Use the manual way (int freqs[11]={0,0,0,0,...}) for readability unless there is a possibility that you may one day create a larger 'freqs array'.

The time it takes to process is negligible and you shouldn't worry about that unless you are pushing the limits with game programming. Always choose readability over speed.

2006-11-17 07:26:48 · answer #2 · answered by Mindlessfun 3 · 1 0

actually we can write first one with
int freqs[11]={0}
will make all elements zero

2006-11-17 07:44:40 · answer #3 · answered by Anonymous · 2 0

for(int i=0;i<=10;i++){

2006-11-17 07:18:32 · answer #4 · answered by ♣valentine melons♣ 4 · 0 1

the second one:
for(int i=0;i<=10;i++){

2006-11-17 07:27:22 · answer #5 · answered by Anonymous · 0 1

surely, the second one.

2006-11-17 10:52:09 · answer #6 · answered by ryan s 1 · 0 1

fedest.com, questions and answers