A different kind of C language

Source: Internet
Author: User

1. Priority of uncommon symbols in C language:
(1). The priority of the symbol is higher than the symbol *, so *p.f should write (*p). F.


(2). The symbol [] has precedence over the symbol *, so int *p[] and int (*p) [] are two different arrays, the former is an array of type int * and the latter is an int array (the array is a two-dimensional array).
int a = 1;
int *b = &a;
int c[2][2] = {{2,3},{4,5}};


int *p[2] = {&a,b};
int (*OP) [2];
op = c;


printf ("The element stored in the array p is the pointer address:%d%d\n", p[0], p[1]);
printf ("The pointer element inside the array p points to the content:%d%d\n", *p[0], *p[1]);
printf ("Array op is actually a pointer to a two-dimensional array of n rows 2 columns:%d%d\n", op[0], op[1]);


(3). The priority of the symbol () is higher than the symbol *, so int *f () is a function named F and the return pointer is an int * type variable, and int (*f) () is a pointer to a function.


(4). Sign = = and! = has a higher precedence than an assignment statement.


2. C Some uncommon statements:
(1). Int (* f ()) () a function that returns the type as a function pointer.


(2). Int (* f ()) [m] returns a pointer to an array of n rows m columns, which is an int (*) [] type variable.


(3). Int (* f[]) is an array that holds an array of function pointers for functions that return a value of type int and whose argument is null.


3. Function Pointers:
(1). function pointer effect:
Pass to other functions as arguments
As the return value of a function
Save in Array
Point to a different function
Call the underlying function


(2). The function pointer should be compatible with the function it points to, and the specific format of the function pointer declaration is "point to function return value type (*F) (parameter to function)".


(3). Pointer Assignment method:
Explicit conversions: F = &func; (Func is a function, f is a function pointer)
Implicit conversions: F = func;


(4). Call of the pointer function:
Display call: *f ();
Implicit invocation: f ();

A different kind of C language

Related Article

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.