logo

How to return an array from a function

#include <stdio.h> #include <stdlib.h> #include <string.h> void getNextFive(int x, int* result) { int i; for (i = 0; i < 5; i++) { result[i] = x + i + 1; } } int main(int argc, char* argv[]) { int x = 5; int arr[5]; getNextFive(x, arr); int i; for (i = 0; i < 5; i++) { printf("%d ", arr[i]); } return 0; }

Courses with this lesson