Home > Enterprise >  How to print a function with prinf()?
How to print a function with prinf()?

Time:06-10

So, i've this code, but i dont know how to print result of a function foo()

#include <stdio.h>

void foo(int arr[]){
    int *sum = 0;
    int product = 1;
 
    for(int i = 0; i < sizeof(*arr); i  ){
        sum  = arr[i];
    }
    for(int i = 0; i < sizeof(*arr); i  ){
        product *= arr[i];
    }

    printf("%d\n", *sum);
    printf("%d\n", product);
}

int main(){
    int arr[] = {1,2,3,4,5};
    foo(arr);
    return 0;
}

i've been tried just to do printf(arr()); but it isn't workded, what i do incorectlly?

CodePudding user response:

Try using sumin place of *sum.

int sum = 0;
printf("%d\n", sum);

It should work.

  •  Tags:  
  • c gcc
  • Related