c-compiler/test.c
2026-04-16 23:47:42 +03:00

55 lines
1.0 KiB
C

void printf(char*, ...);
int fibonacci(int n) {
if (n < 2)
return 1;
return fibonacci(n - 1) + fibonacci(n - 2);
}
void change_first(char otus[5]) {
otus[0] = 115;
}
struct Otus;
struct Otus {
int field;
int second[2];
};
void update(struct Otus potus) {
potus.field = 20;
}
void update_ptr(char* ptr) {
*ptr = 50;
}
int main() {
char text[30] = "10th fibonacci number is %d!\n";
printf(text, fibonacci(10));
char somelist[5] = { 1, 2, 3, 4, 5 };
char* somelist_ptr = somelist;
change_first(somelist);
printf("first element: %d!\n", somelist[0]);
printf("first element via ptr: %d!\n", somelist_ptr[0]);
struct Otus otus = { 5, { 7, 3 } };
update(otus);
printf("first field: %d!\n", otus.field);
printf("second field's second element: %d!\n", otus.second[1]);
char hello = 10;
update_ptr(&hello);
printf("hello: %d!\n", hello);
char twod_array[5][5];
twod_array[0][0] = 50;
printf("2d array: %d!\n", twod_array[0][0]);
return 0;
}