Open Metric
Science, Fiction and Me

Today I Learned

C++ range-for-statement

# include

<iostream>
</iostream>

using namespace std;

int main(){
    int v[] = {1,3,5,7};

    for( auto x:v)
    {
      cout << x << endl;
   }

}

What this does is to copy each element of array v into x and print it. For efficiency, we could use instead pointers.

 for(auto& x : v) { cout << &x << endl; } 

A Random #TIL# for You


Most technical TILs will be updated at datumorphism.leima.is/til

By OctoMiao

Last updated