0

this code :

int a[] = {};
    int i,b,o,p,j;
    std::cout<<"a[-2] >> "<<a[-2]<<std::endl;
    std::cout<<"a[-1] >> "<<a[-1]<<std::endl;
    std::cout<<"a[0] >> "<<a[0]<<std::endl;
    std::cout<<"a[1] >> "<<a[1]<<std::endl;
    std::cout<<"a[2] >> "<<a[2]<<std::endl;
    std::cout<<"b >> "<<b<<std::endl;
    std::cout<<"p >> "<<p<<std::endl;
    std::cout<<"j >> "<<j<<std::endl;
    std::cout<<"a[3] >> "<<a[3]<<std::endl;

output like this.. :

a[-2] >> -875679664
a[-1] >> -2
a[0] >> 7470856
a[1] >> 1993175021
.
.
j >> 7470856
a[3] >> 7470928

help me please, i don't really known

thanks.. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

drescherjm
  • 10,365
  • 5
  • 44
  • 64
  • 4
    What did you expect? Your program has undefined behavior since you read uninitialized variables. – Ted Lyngmo Jul 17 '20 at 13:01
  • 2
    Why did you tag it as `C`? The code is without a doubt not C. – mch Jul 17 '20 at 13:01
  • 2
    Two words: [Undefined Behaviour](https://en.wikipedia.org/wiki/Undefined_behavior). Compiler is allowed to do anything with this code, even make [demons fly out of your nose](http://catb.org/jargon/html/N/nasal-demons.html) – Yksisarvinen Jul 17 '20 at 13:01
  • 2
    `int a[] = {};` no index of a is valid. – drescherjm Jul 17 '20 at 13:04
  • 2
    `int a[] = {};` is an array of `0` elements, at least that's what the compiler says: https://godbolt.org/z/oE1Yx8 – mch Jul 17 '20 at 13:04

0 Answers0