Skip to content

Instantly share code, notes, and snippets.

@drpventura
Created August 28, 2016 18:42
Show Gist options
  • Select an option

  • Save drpventura/b56bd45fecd8875eb4524dec2777ce35 to your computer and use it in GitHub Desktop.

Select an option

Save drpventura/b56bd45fecd8875eb4524dec2777ce35 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <algorithm>
using namespace std;
void cube(int& l) {
l = l * l * l;
}
int main() {
int nums[] {1, 3, 5, 7, 11};
int before = -75;
// for (int i = 0; i < 5; i++) {
// cout << "nums[" << i << "] = " << nums[i] << endl;
// }
// for (int& n : nums) {
//// n = n * 2;
// n *= 2;
// cout << n << endl;
// }
// for (auto& n : nums) {
// cube(n);
// }
// for_each(begin(nums), end(nums), cube);
for_each(begin(nums), end(nums), [](int& l){
l = l * l * l;
});
// for (auto n : nums) {
// cout << n << ' ';
// }
for_each(begin(nums), end(nums), [](auto l){
cout << l << ' ';
});
cout << endl;
int after = 123;
// cout << "nums[5] = " << nums[5] << endl;
// cout << "nums[-1] = " << nums[-1] << endl;
//
// for (int i = 6; i < 20; i++) {
// nums[i] = nums[i] * 2;
// cout << "nums[" << i << "] = " << nums[i] << endl;
// }
// cout << "before = " << before << endl;
// cout << "after = " << after << endl;
// cout << "nums[10000] = " << nums[10000] << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment