cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Array Values
Array Values
Nov 26, 2013 at 10:18pm UTC
umax11
(1)
Could anyone explain why this returns -2??
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d,e = 3;
int billy[5] = {a,b,c,d,e};
cin.ignore();
cout<< a <<"\n";
cin.get();
}
Nov 26, 2013 at 10:30pm UTC
Chervil
(7320)
It could output any number at all, since
a
is not initialised.
Only
e
and
billy[4]
have a known value of 3. The other variables contain whatever happens to already be in those memory locations, usually referred to as 'garbage'.
Topic archived. No new replies allowed.