C is used almost everywhere, enough said. This is a short overview of the language. To run a C file, you frist compile the file into an object file and then the linker links it to any other compiled file that it needs and creates an executable.
/* INIT POINTER
p is a pointer to int and is initialized with address of apples
*/intapples=5;int*p=&apples;// p = apples' address/* DEREFERENCE POINTER
- dereference p (get the value of the address that p is pointing at)
- add 6 to dereferenced p
- place result in oranges
*/intoranges=*p+6;// oranges = 11/* POINTER VALIDATION
you initialize the poitner to 0
which is null/nullptr and before you use
the pointer, check if it's valid with an if
*/int*g=0;if(g){// g is not null, do stuff with g}/* ARRAYS AND POINTERS
*/intvalues[]={0,1,2,3,4};int*ptr=values;// pointing to first element (0)int*last=&values[4];// pointing to last (4)++ptr;// pointing to second element (1)ptr+=3;// pointing to last element (4)/* FUNCTION POINTERS
*/intcelsius_to_f(intc){returnc*9/5+32;}typedefint(*converter)(intfrom);converterconvert=celsius_to_f;printf("%d\n",convert(34));
Structures
1
2
3
4
5
6
7
8
typedefstruct{floatred;floatgreen;floatblue;floatalpha;}color;colormy_color={1,0,0,1};// red
#include <stdlib.h>
/* malloc
allocates number of bytes,
returning pointer to address of first byte
*/typedefstruct{intvalue;}MyStruct;MyStruct*a=(MyStruct*)malloc(sizeof(MyStruct));MyStruct*b=(MyStruct*)malloc(sizeof(MyStruct));MyStruct*c=(MyStruct*)malloc(sizeof(MyStruct));a->value=1;b->value=2;c->value=3;/* free
releases the memory given a pointer
*/free(a);free(b);free(c);