reset password
Author Message
lakerfan94
Posts: 143
Posted 12:24 Mar 18, 2016 |

When you declare an array of ints, does c++ provide default values for that array? If so, are those default values 0?

kknaur
Posts: 540
Posted 12:27 Mar 18, 2016 |

Never assume that it does.  This is something that is compiler specific and will also vary if you are using a static array allocated on the stack vs a dynamic array allocated on the heap.  Pretty much some compilers may initialize your arrays with default values of 0 based on the datatype and other compilers will not.  To make your program as compatible with as many compilers as possible you should always initialize the array yourself.

lakerfan94
Posts: 143
Posted 14:06 Mar 18, 2016 |

Ok @KKNAUR. Thank you.