Adventures in C
If you’re more familiar with Python and you want to learn C you’ll need to tackle pointers…
Let’s look at an example :
The first thing you may notice is that there is no need for a “return” from the function….
Example 1 – Pointers
#include<stdio.h>
void tripler(int *p);
int main(){
int num = 5;
int *ptr;
ptr = #
tripler(ptr);
printf("%d",*ptr);
}
void tripler(int *p){
*p = *p * 3;
}
![](https://redandgreen.co.uk/wp-content/uploads/2021/09/pointer-1.png)
pointer and address of operator
Example 2 – Pointer that updates conditionally, based on values read from an array
![](https://redandgreen.co.uk/wp-content/uploads/2021/09/pointer_code-774x1024.png)
Example 3 – How to convert seconds into h:m:s
![](https://redandgreen.co.uk/wp-content/uploads/2021/09/code3-917x1024.png)
Example 4 – Hundreds, tens, units from a 3 digit integer.
![](https://redandgreen.co.uk/wp-content/uploads/2021/09/htu-1024x666.png)
2d Arrays in C
![2d-array-in-c](https://redandgreen.co.uk/wp-content/uploads/2021/09/c-2darray-edited.png)
![Swap using pointers](https://redandgreen.co.uk/wp-content/uploads/2021/09/swapper-1.gif)