-
Notifications
You must be signed in to change notification settings - Fork 0
/
polygroundwork.cpp
75 lines (62 loc) · 1.59 KB
/
polygroundwork.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// g++ polygroundwork.cpp -o test $(sdl-config --libs --cflags)
// Refresher course for how C++/C works
//
#include <stdlib.h>
#if defined(_MSC_VER)
#include "SDL.h"
#else
#include "SDL/SDL.h"
#endif
#include <stdio.h>
#include <math.h>
#define PI (3.14159265)
SDL_Surface *screen;
void printarray(unsigned int array[], int array_length){
//for (int i = 0; i < arraylength, i++)
for (int i =0; i < array_length; i++, array++){
printf("array elem[%d]\n",*array);
}
return ;
}
void printarray2(unsigned int *array, int array_length){
//for (int i = 0; i < arraylength, i++)
for (int i =0; i < array_length; i++, array++){
printf("array elem[%d]\n",*array);
}
return ;
}
void printptr(unsigned int *ptr) {
printf("ptr elem = 0x%x, %d\n",ptr,*ptr);
}
typedef struct Coord {
int x;
int y;
int bla;
} ;
typedef Coord* CoordPtr;
void printCoord(Coord &ptr) {
printf("ptr elem = 0x%x, x=%d, y=%d\n",&ptr,ptr.x,ptr.y);
ptr.x = 151;
}
/*
recap on C peculiarities. Pointers, passing by value/reference, passing arrays.
classes
*/
int main(int argc, char *argv[]){
unsigned int array1[] = {1,2,3,4,5};
printarray(array1,sizeof(array1)/sizeof(unsigned int));
printptr(array1+2);
array1[2] = 12;
printptr(array1+2);
printarray(array1,sizeof(array1)/sizeof(unsigned int));
Coord xxx = {
101, // should be x
2320, // should be y
-1}; // should be bla
printf("bla = %d\n",xxx.bla);
printf("x = %d\n",xxx.x);
printf("y = %d\n",xxx.y);
printCoord(xxx);
printCoord(xxx);
printarray2(array1,sizeof(array1)/sizeof(unsigned int));
}