Two-level pointers, array pointers, two-dimensional arrays, and pointer arrays can be passed in as function parameters in the argument __ function

Source: Internet
Author: User

1, the rule of reference:

A. When a level two pointer acts as a function parameter, it is a level two pointer, an array of pointers, and an address of a first-hand pointer.
B. When the array pointer acts as a function parameter, the function argument is a two-dimensional array, and the array pointer
C. When a two-dimensional array is used as a function parameter, the function argument is a two-dimensional array, and the array pointer
D. When an array of pointers is used as a function parameter, it is an array of pointers, a level two pointer, and the address of a first-hand pointer as a function argument.

2. Example verification:

 #include <stdio.h> #include <stdlib.h> void fun1 (int **pp) {printf ("fun1\n");} void fun2 (int (*a_p) [5]) {printf ("fun2\n");} void Fun3 (int t_d_a[][5]) {printf ("fun3\n");} void Fun4 (int *p_a[

5]) {printf ("fun4\n");}          int main () {int *p_a[5];      pointer array int **pp = NULL;        Second-level pointer int *p = NULL;      First level pointer int t_d_a[5][5];             Two-dimensional array int a[5];    one-dimensional array int (*a_p) [5] = &a;
    Array pointer fun1 (P_A);
    FUN1 (PP);
    FUN1 (&P);
    FUN1 (t_d_a);
    FUN1 (a_p);

    printf ("\ n");
    Fun2 (p_a);
    FUN2 (PP);
    Fun2 (&P);
    Fun2 (t_d_a);
    Fun2 (a_p);

    printf ("\ n");
    FUN3 (p_a);
    FUN3 (PP);
    FUN3 (&P);
    FUN3 (t_d_a);
    FUN3 (a_p);

    printf ("\ n");
    Fun4 (p_a);
    FUN4 (PP);
    Fun4 (&P);
    Fun4 (t_d_a);
    Fun4 (a_p);

    printf ("\ n");
    System ("pause");
return 0; }

The above code I let go of any of the comments, and the error is not compatible with the type of the formal participation argument.
PS: Debug environment is vs2013

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.