1

Following code is undefined behavior?

int main()
{
    int x[1] = { 0 };
    x + 1; // This is not undefined behavior.
    int y = 0;
    &y + 1; // Is this undefined behavior?
}

I want to use <algorithm> functions with non‐array object. e.g.

#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
    int x;
    // Is this undefined behavior?
    std::copy(&x, &x + 1, std::ostream_iterator<int>(std::cout));
}
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Egtra
  • 111
  • 2

0 Answers0