0

Int n = 0; ... cin >> n; cant understand why i need to initialize n=0 at the beginning, while my target is random n?

Hey dear friends, im just trying right now to make a prog of prime numbers test. In the sample ive met there is int n=0 in the beginning, and than i need to input a various n. I cant understand why do i need to initialize n=0 if my n is random number ?

9th Jan 2017, 7:06 PM
jonathan baranov
jonathan baranov - avatar
2 Respostas
0
Is for good practice, remember when create a variable you assign a space of memory, but you can't know if that part of memory was used before, so to avoid use a datum that you don't want to use; you assign it. in this case int n = 0;. Or at least that told me my teacher when i was in school. i hope this can clear you doubt.
9th Jan 2017, 7:29 PM
Alfonso Alejandro Rodriguez Nolasco
0
Thank you very much it cleared me a lot!:)
9th Jan 2017, 8:00 PM
jonathan baranov
jonathan baranov - avatar