What happens if I just declare the variable "sum" but don't put the initial value? For instance, if instead of saying "int sum = 0;" , I said " int sum;" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What happens if I just declare the variable "sum" but don't put the initial value? For instance, if instead of saying "int sum = 0;" , I said " int sum;"

3rd Jan 2016, 10:16 PM
Lucas
Lucas - avatar
3 Answers
0
Generally the initial value of integer is a random number, not sure -2. Usually it's a rather long number like 16437843 or -854270. You can easily make sure of it with this code: int arr[20]; for (int i = 0; i < 20; ++i) cout << arr[i] << endl;
8th Apr 2016, 12:32 AM
Дмитрий Иванов
Дмитрий Иванов - avatar
0
The initial value depends on the compiler implementation.
16th Jun 2016, 8:17 PM
VPA
VPA - avatar
0
It gives an error as undefined variable as it is declared but not defined
1st Jul 2016, 8:36 AM
Midhun Mathew