Skip to content

Instantly share code, notes, and snippets.

@YoniTsafir
Created March 2, 2011 19:06
Show Gist options
  • Save YoniTsafir/851493 to your computer and use it in GitHub Desktop.
Save YoniTsafir/851493 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
void main()
{
int a = 1, b = 2;
int arr[] = {1, 3, 5, a, b};
int *p = arr + 1;
int **q = &p;
int ***crazy = new int**[*(arr + 4)];
crazy[0] = q;
crazy[1] = new int*[*(p - 1)];
crazy[1][0] = &arr[2];
cout << arr[crazy[0][0][1] - a] + arr[crazy[1][0][1]] + b << endl;
delete [] crazy[1];
delete [] crazy;
}
#include <iostream>
using namespace std;
struct A
{
int a;
};
struct B
{
int b;
A* a;
int aSize;
};
struct C
{
int c;
B** b;
int bSize;
};
void main()
{
A a1 = {0};
A a2 = {2};
A a3 = {4};
B b1;
b1.b = a2.a * a3.a;
b1.aSize = 3;
b1.a = new A[b1.aSize];
b1.a[0] = a1;
b1.a[1] = a2;
b1.a[2] = a3;
B b2;
b2.aSize = 20;
b2.a = new A[b2.aSize];
C c;
c.c = 0;
for (int i = 0; i < b1.aSize; i++)
{
c.c += b1.a[i].a;
}
c.bSize = c.c / 2;
c.b = new B*[c.bSize];
c.b[0] = &b1;
c.b[1] = &b2;
for (int i = 0; i < c.bSize; i++)
{
for (int j = 0; j < c.b[i]->aSize; j++)
{
cout << c.b[i]->a[j].a << endl;
}
}
}
#include <iostream>
using namespace std;
void main()
{
int arr[] = {1, 3, 7, 9, 2, 4, -1, -3};
int size = sizeof(arr) / sizeof(arr[0]);
int i = 0;
while(i < size)
{
if (i + 1 != size)
{
cout << arr[i] + arr[i + 1];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment