Skip to content

Instantly share code, notes, and snippets.

@PHPirates
Created October 6, 2018 10:47
Show Gist options
  • Save PHPirates/4f25eb30eadabfe5d988c0d6c4b760d7 to your computer and use it in GitHub Desktop.
Save PHPirates/4f25eb30eadabfe5d988c0d6c4b760d7 to your computer and use it in GitHub Desktop.
Quick reference on C pointers
/**
* @file pointers
* @brief A hello world example.
*
* This a file with some pointers. Documentation can be generated with doxygen.
*/
#include <stdio.h>
/**
* Calculate a=a+b, b=a*b.
*
* @param a An int.
* @param b Another int.
*/
static void add_and_multiply(int *a, int *b) {
int oldA = *a;
*a = *a + *b;
*b = oldA * *b;
}
void function_of_array(char *an_array) {
an_array[0] = '42';
}
int main()
{
char some_array[1];
function_of_array(some_array);
int a = 7;
int b = -5;
add_and_multiply(&a, &b);
printf("a=%d b=%d\n", a, b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment