mirror of https://github.com/aamine/cbc
83 lines
1.4 KiB
Plaintext
83 lines
1.4 KiB
Plaintext
import stdio;
|
|
import string;
|
|
|
|
int global_x = 0;
|
|
int common_x;
|
|
|
|
struct s {
|
|
int* ptr;
|
|
};
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
int x, y;
|
|
static int static_x = 0;
|
|
static int scomm_x;
|
|
int*[2] ptrs;
|
|
struct s s;
|
|
int* ptr;
|
|
int[8] integers;
|
|
char[8] buf;
|
|
char *p = buf;
|
|
memcpy(buf, "Hello", 8);
|
|
|
|
// local variable
|
|
x = 1;
|
|
printf("%d", x);
|
|
|
|
x = 77;
|
|
y = 77;
|
|
x = y = 2;
|
|
printf(";%d;%d", x, y);
|
|
|
|
// parameter
|
|
argc = 3;
|
|
printf(";%d", argc);
|
|
|
|
// global variable, common symbol
|
|
global_x = 4;
|
|
common_x = 5;
|
|
printf(";%d;%d", global_x, common_x);
|
|
|
|
// static global variable, static common symbol
|
|
static_x = 6;
|
|
scomm_x = 7;
|
|
printf(";%d;%d", static_x, scomm_x);
|
|
|
|
// local array with pointer
|
|
ptrs[0] = &x;
|
|
*ptrs[0] = 8;
|
|
printf(";%d;%d", *ptrs[0], x);
|
|
|
|
// local struct with pointer
|
|
s.ptr = &x;
|
|
x = 9;
|
|
printf(";%d", *s.ptr);
|
|
|
|
// local pointer
|
|
ptr = &x;
|
|
*ptr++ = 10;
|
|
ptr--;
|
|
printf(";%d", *ptr);
|
|
|
|
// local array
|
|
integers[0] = integers[1] = integers[2] = integers[3] = 777;
|
|
ptr = integers;
|
|
*ptr++ = 11;
|
|
printf(";%d;%d", integers[0], integers[1]);
|
|
|
|
// local array with pointer arithmetic
|
|
*(p + 1) = 'S';
|
|
printf(";%c", p[1]);
|
|
|
|
// local array with pointer arithmetic
|
|
ptrs[0] = NULL;
|
|
ptrs[1] = &x;
|
|
**(ptrs + 1) = 12;
|
|
printf(";%d", *ptrs[1]);
|
|
|
|
puts("");
|
|
return 0;
|
|
}
|