Created
October 6, 2018 10:47
-
-
Save PHPirates/4f25eb30eadabfe5d988c0d6c4b760d7 to your computer and use it in GitHub Desktop.
Quick reference on C pointers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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