Skip to content

Instantly share code, notes, and snippets.

@retorillo
Created July 25, 2018 06:05
Show Gist options
  • Save retorillo/add73c7c94d0031db90267e97d01b41c to your computer and use it in GitHub Desktop.
Save retorillo/add73c7c94d0031db90267e97d01b41c to your computer and use it in GitHub Desktop.
C++ Pointer Increment Demo
#include <vector>
int main() {
struct t{ int i1; int i2; };
std::vector<t> v;
v.push_back(t {1, 2});
v.push_back(t {3, 4});
v.push_back(t {5, 6});
for(int l = v.size(), c = 0; c < l; c++)
printf("%d, ", (v.data() + c)->i2);
}
// Result: 2, 4, 6,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment