A1 - hello world
anatomy of a C program
#include <stdio.h> // importing external code, here importing printf
// start of the program
int main() { // entry point; int denotes that an integer is returned
printf("Hello World!\n"); // semi colons indicate the end of a line
return 0; // returning zero from main indicates successful execution
}
header files
- declare available functions and variables
// defining constants
#define CAR_WHEEL_COUNT 4
// declaring available functions
void drive();
int get_id();
char* get_vin();
- above is the header file,
car.h
#include "car.h"
// contains actual implementation
void drive() {
printf("Driving");
}
...
-
here, the header file is imported and the functions are defined
-
standard library key aspects:
<string.h>for string manipulation<stdio.h>for input/output functions<sdlib.h>for memory allocation and mathematical conversion functions<math.h>for common maths functions<ctype.h>for character manipulation functions- see more