Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
sum of arrays
//gcc 5.4.0 #include <stdio.h> #include <malloc.h> int* funcSum(int a[], int b[]) { //int sum = 10; //we can return a local variable to main //static int sum[] = {0,0}; // we cannot return the array as such as its the address return sum, use static or malloc int *sum = malloc(10*sizeof(int)); for (int i=0; i<2; i++) { sum[i] = a[i] + b[i]; } //printf("sum[%d] = %d\n",0,sum[0]); return sum; } int main(void) { //int a=5,b=7; int a[2] = {1,2}; int b[2] = {1,2}; int *result = funcSum(a,b); //printf("Hello, world!\n"); for (int i=0; i<2; i++) { printf("result[%d] = %d\n",i,result[i]); } return 0; }
run
|
edit
|
history
|
help
0
150115_MatrizTodosDistintos
Ppp
second P
json string formatter
150109_RecursividadPrimo
structt
pth_trap.c
data types and printf
1
String copy