Recent Posts
printf("ho_tari\n");
sumArray2 본문
#include <stdio.h>
int sumArray(const int *pArr, int size)
//int sumArray(int pArr[], int size)
//int sumArray(int pArr[10], int size)
{
int result = 0;
for (int i = 0; i < size; ++i)
{
result = result + pArr[i]; //*(pArr + i)
}
return result;
}
int main(void)
{
int nums[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int total = sumArray(nums, 10); // sumArray(&nums[0])
//int total = sumArray(nums + 5, 5); // &nums[5]
printf("sum: %d\n", total);
return 0;
}
<compile 결과>
'C' 카테고리의 다른 글
sumOne2Ten (0) | 2023.09.01 |
---|---|
sumMatrix (0) | 2023.09.01 |
sumArray (0) | 2023.09.01 |
stringArray (0) | 2023.09.01 |
star3 (0) | 2023.09.01 |