Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
#include <stdio.h> /* Pass-by-value: caller's x is NOT changed */ void increment_val(int x) { x++; printf("inside increment_val: x = %d ", x); } /* Pass-by-pointer: caller's variable IS changed */ void increment_ptr(int *x) { (*x)++; printf("inside increment_ptr: *x = %d ", *x); } /* Return two values via output parameters */ void min_max(const int *arr, int len, int *out_min, int *out_max) { *out_min = *out_max = arr[0]; for (int i = 1; i < len; i++) { if (arr[i] < *out_min) *out_min = arr[i]; if (arr[i] > *out_max) *out_max = arr[i]; } } int main(void) { int a = 10; increment_val(a); printf("after increment_val: a = %d ", a); /* still 10 */ increment_ptr(&a); printf("after increment_ptr: a = %d ", a); /* now 11 */ int data[] = {5, 3, 9, 1, 7, 2}; int mn, mx; min_max(data, 6, &mn, &mx); printf("min = %d, max = %d ", mn, mx); /* 1, 9 */ return 0; }
Result
Open