#include // For printf #include // For malloc #include"er_IN2060.h" int main(){ /* Part 1: Variables */ // In C variables are weakly typed int a = 4; char b = 'h'; printf("4 + h is: %i\n", a+b); /* Part 2: If/else Statements */ if(b > a){ a += 4; } else{ a += 2; } printf("%i\n", a); /* Part 3: Pointers */ int* pointer = malloc(sizeof(int)*1); pointer[0] = 3; printf("A pointer: %x\n", pointer); free(pointer); /* Part 4: Strings and memory allocation */ // Strings are represented by placing several chars after each other in memory // Memory must be allocated for a string char* string = "Hello!"; char* string_2 = malloc(sizeof(int)*7); string_2[0] = 'H'; string_2[1] = 'e'; string_2[2] = 'l'; string_2[3] = 'l'; string_2[4] = 'o'; string_2[5] = '!'; string_2[6] = 0; printf("%s\n", string_2); /* Part 5: Loops */ for(int i = 0; i < 6; i++){ printf("%i\n", i); } while(*string_2){ printf("%c\n", string_2[0]); string_2 += 1; } /* Part 6: Functions and header files */ printf("Er det IN2060? %s\n", er_IN2060("IN2060")); }