learning-c/main.c
2026-05-21 23:21:31 +02:00

111 lines
No EOL
3 KiB
C

// Welcome to my journey of learning the fuckass language that is C
#include <stdio.h>
#include <string.h>
// STRUCTURE TEST
struct man {
char firstname[20];
char surname[20];
int age;
int weight;
char relationship_status[10];
};
int multiply(int num_one, int num_two) {
int result = num_one*num_two;
return result;
}
int main() {
// HELLO WORLD SECTION
printf("HELLO WORLD BELOW:\n"); // DIVIDER
char first[] = "Hello";
char second[] = "World";
printf("%s %s", first, second);
// IF/ELSE STATEMENT
printf("\n\nIF/ELSE STATEMENT BELOW:\n"); // DIVIDER
int num = 67;
if (69<num) {
printf("69 is smaller than %d ", num);
} else {
printf("69 is larger than %d ", num);
}
// SWITCH STATEMENT
printf("\n\nSWITCH STATEMENT BELOW:\n"); // DIVIDER
int meme = 1337;
switch (meme) {
case 13:
printf("she said she was twelve!");
break;
case 21:
printf("haha 9+10");
break;
case 67:
printf("lolol 67");
break;
case 69:
printf("nice");
break;
case 420:
printf("weed..");
break;
case 1337:
printf("you are elite");
break;
case 80085:
printf("do NOT put this number into a calculator");
break;
default:
printf("Sorry I do not recognise this meme");
break;
}
// WHILE LOOP
printf("\n\nWHILE LOOP BELOW:\n"); // DIVIDER
int a=1,b=7;
while (a!=b) {
a++;
b-=1;
printf("int a=%d AND int b=%d\n", a, b);
}
// FOR LOOP
printf("\n\nFOR LOOP BELOW:\n"); // DIVIDER
for (int i=0; i<=3; i++) {
printf("i=%d\n", i);
}
// FUNCTION
printf("\n\nFUNCTION (MULTIPLY) BELOW:\n"); // DIVIDER
printf("%d * %d = %d", 5, 30, multiply(5,30));
// ARRAY
printf("\n\nARRAY BELOW:\n"); // DIVIDER
int arr[] = {21, 67, 69, 420};
printf("arr[0]=%d\narr[1]=%d\narr[2]=%d\narr[3]=%d", arr[0], arr[1], arr[2], arr[3]);
// POINTER
printf("\n\nPOINTER BELOW:\n"); // DIVIDER
int victim=7;
int *victim_pointer=&victim;
printf("pointer of int victim is: %p\n", victim_pointer);
int derefrencing_operator=*victim_pointer;
printf("derefrencing operator of *victim_pointer is: %d\n", derefrencing_operator);
int **double_ptr = &victim_pointer;
printf("double pointer of the &victim_pointer is: %p", double_ptr);
// STRING
printf("\n\nSTRING BELOW:\n"); // DIVIDER
char message[22]="Hello, world. Again...";
printf("%s", message);
// STRUCTURES
printf("\n\nSTRUCTURE (peter) BELOW:\n"); // DIVIDER
struct man PETER={"Peter", "Griffin", 35, 150, "married"};
printf("Our man is named %s %s, he is %d years old, he weights %dkg and his relationship status is %s.", PETER.firstname, PETER.surname, PETER.age, PETER.weight, PETER.relationship_status);
// END
return 0;
}