![]() |
Init array with a non-zero value
This is embarrasing, but I've always thought:
int variable[10] = {9}; will init all items to 9. But it does not. Any cool way to init to a non-zero value besides a for-loop? Thanks in advance. |
Re: Init array with a non-zero value
:
still just a loop under the hood |
Re: Init array with a non-zero value
For smaller arrays, you can do this
:
|
Re: Init array with a non-zero value
Quote:
:
|
Re: Init array with a non-zero value
memset is a function that can be pretty handy sometimes. Even thought it may not function as expected with your "int" it is good to know about it when you are using char's.
http://www.cplusplus.com/reference/c...ng/memset.html |
| All times are GMT -5. The time now is 11:19 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC