RicardasSim

for auto

Mar 7th, 2019
568
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.  
  7.     int x[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  8.  
  9.     for( auto y : x ) {
  10.         cout << y << " ";
  11.     }
  12.     cout << endl;
  13.    
  14.     for( auto &y : x ) {
  15.         y = 1;
  16.         cout << y << " ";
  17.     }
  18.     cout << endl;
  19.  
  20.     for( auto y : x ) {
  21.         cout << y << " ";
  22.     }
  23.     cout << endl;
  24.    
  25. }
  26.  
  27. /*
  28. output:
  29.  
  30. 1 2 3 4 5 6 7 8 9 10
  31. 1 1 1 1 1 1 1 1 1 1
  32. 1 1 1 1 1 1 1 1 1 1
  33.  
  34. */
Advertisement
Add Comment
Please, Sign In to add comment