Tutorial by Examples

A common pattern in C, to easily imitate returning multiple values from a function, is to use pointers. #include <stdio.h> void Get( int* c , double* d ) { *c = 72; *d = 175.0; } int main(void) { int a = 0; double b = 0.0; Get( &a , &b ); pr...
int getListOfFriends(size_t size, int friend_indexes[]) { size_t i = 0; for (; i < size; i++) { friend_indexes[i] = i; } } C99C11 /* Type "void" and VLAs ("int friend_indexes[static size]") require C99 at least. In C11 VLAs are optional. */ void getLis...
In C, all function parameters are passed by value, so modifying what is passed in callee functions won't affect caller functions' local variables. #include <stdio.h> void modify(int v) { printf("modify 1: %d\n", v); /* 0 is printed */ v = 42; printf("modify 2:...
The order of execution of parameters is undefined in C programming. Here it may execute from left to right or from right to left. The order depends on the implementation. #include <stdio.h> void function(int a, int b) { printf("%d %d\n", a, b); } int main(void) { ...
Most examples of a function returning a value involve providing a pointer as one of the arguments to allow the function to modify the value pointed to, similar to the following. The actual return value of the function is usually some type such as an int to indicate the status of the result, whether ...

Page 1 of 1