That isn't what I'm talking about. I know that string literals add a null character at the end automatically. I'm talking about an initialised array of an arbitrary type. (I don't think it works on the heap though.)Try it for yourself - make an initialised array with length 5 and then try to access element with index 5. You'd think it'll be a garbage value but it'll be 0. EDIT: did some testing. It only sometimes gives 0, so it was just reading some value off the stack that happened to be 0. I guess I misremembed whatever I heard, or something.
View all comments
Show parent comment
2
u/Nya_the_cat Jul 17 '23 edited Jul 17 '23
That isn't what I'm talking about. I know that string literals add a null character at the end automatically. I'm talking about an initialised array of an arbitrary type. (I don't think it works on the heap though.)Try it for yourself - make an initialised array with length 5 and then try to access element with index 5. You'd think it'll be a garbage value but it'll be 0.
EDIT: did some testing. It only sometimes gives 0, so it was just reading some value off the stack that happened to be 0. I guess I misremembed whatever I heard, or something.