C lang:Array and Pointer formal parameter

Test

Xx_Formal parameter


Formal parameter are local variable. It's private to the function.

Ax_Array formal parameter

#include<stdio.h>
#define SIZE 10
int sum(int ar[], int n);
int main(void)
{
    int marbles[SIZE] = {20, 10, 5, 39, 4, 16, 19, 26, 31, 20};
    long answer;

    answer = sum(marbles, SIZE);
    printf("The totla number of marbles is %ld.\n",answer);
    printf("The size of marbles is %zd bytes.\n",sizeof marbles);

    return 0;
}
int sum(int ar[], int n)
{
    int i;
    int total = 0;

    for(i = 0; i < n; i++)
        total += ar[i];
    printf("The size of ar is %u bytes.\n", sizeof ar);

    return total;
}
---
||=== Build file: "no target" in "no project" (compiler: unknown) ===|
C:\Users\***\Desktop\1231.c||In function 'sum':|
C:\Users\***\Desktop\1231.c|22|warning: 'sizeof' on array function parameter 'ar' will return size of 'int *' [-Wsizeof-array-argument]|
C:\Users\***\Desktop\1231.c|15|note: declared here|
||=== Build finished: 0 error(s), 1 warning(s) (0 minute(s), 1 second(s)) ===|

C lang:Array and Pointer formal parameter

Bx_Pointer formal parameter

C ensures that when space is allocated to an array, a pointer to the first


position after the array is still a valid pointer.

上一篇:Jenkins git 多分支选择


下一篇:图说jdk1.8新特性(5)--- 编译器新特性