I'm trying to initialize an array with 10 floating point numbers in it. This would be the only way I know how. Please advise
Code:float array[10] = (1.66,.58,-2.35,0,1.9,0,-.34,0,7.56,-.3);
I'm trying to initialize an array with 10 floating point numbers in it. This would be the only way I know how. Please advise
Code:float array[10] = (1.66,.58,-2.35,0,1.9,0,-.34,0,7.56,-.3);
I tried using 11 instead of 10 in case it needed room for the null character (forgot how that works) but that didn't help any.
Use { }, not ( )
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
haha yeah I just figured that out thanks a lot
First you need {} instead of () when define an array.
Null character is needed for arrays of type char that means strings.
- nm -
"I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe
http://www.Bloodware.net - Developing free software for the community.
The wording of your sentence is odd here, and open to interpretation. Depending on your meaning, you are either right, or wrong:Originally Posted by Micko
The above is perfectly valid. The above character array has been fully initialized, and may be used as you see fit, provided you don't try to use it as a "string". You do not have to have the null character in character arrays. It is not a requirement of arrays of type char.Code:char array[5] = { 'h', 'e', 'l', 'l', 'o' };
However, if you do intend to use it as a C type string, you need to have it null terminated, because that is the definition of a C type string. (An array of characters terminated by a null.)
This is a string because a null character is appended to it. You could use the same initialization on the above array, and no array would be appended, thus it would not be a string.Code:char array[] = "hello";
Quzah.
Hope is the first step on the road to disappointment.