-
Notifications
You must be signed in to change notification settings - Fork 0
/
c_example.doc
43 lines (39 loc) · 1.06 KB
/
c_example.doc
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
Example 1
/* An example to branch into functions by checking if the iteration number is even or odd*/
#include <stido.h>
int main()
{
int counter = 0;
while(counter < 100)
{
++counter;
if(counter & 1 != 0)
{
/* do something if the iteration number is odd */
}
else
{
/* do something if the iteration number is even*/
}
}
return 0;
}
Example 2
/* Change the iteration number to a pointer to int type*/
/* Try hardcode a memory addres to the pointer. Even if the address are conflicted, the designated value can still be written into,
/* half into the counter addres, half into the hardcoded memory address which found to be quite interesting*/
#include <stido.h>
int ocunter = 0 /global variable
int main()
{
int *int_p;
int_p = &counter; /e.g., int_p is assigned to 0x20000000
while(*int_p < 10)
{
++(*int_p);
}
int_p = (int *) 0x20000002U; /type casting is needed in order to be compiled correctly
//int_p = (int *) 0x20000004U;
*int_p = 0xDEADBEEF;
return 0;
}