C Study notes-pointers

Source: Internet
Author: User

Pointers and Arrays
    intA[] = {1,2,3,4,5}; int*p; P=A; printf ("*a =%d\n",*a); printf ("*p =%d\n",*p); printf ("a[1] =%d\n", a[1]); printf ("p[1] =%d\n"-P:1]);

The array name is the first address of the array. The above output is the same. The array name is basically equivalent to the pointer. But a is a constant, can not do a++ or a+=1, and the pointer P can be.

pointer arrays and Arrays pointers
Data type * variable name []// First it is an array, the element of the array is a pointer, which means that each element stores the contents of an address int *a[5];    Data type (* variable name) []// First it is a pointer to an array int (*a) [5];
pointer functions and function pointers
Type identifier * function name (parameter table)// pointer function, which is a function, the return value is a pointer int *f (x, y); type identifier (* function name) ( Parameter table)// function pointer int (*f) (int  x); // The function address is assigned to the function pointer f = &= function // Use function pointer to call functions x = (*f) ();   // = f (  );
Pointer calculation

Self-increment: increase or decrease by the length of the data type it refers to

    int Ten ;     int *p;     = &A;    printf ("%p\n", p);    P+ +;    printf ("%p\n", p);

Operation Result:

0X7FFF5FBFF7FC 0x7fff5fbff800

You can see two results with a difference of 4, which is the byte length of int.

C Study notes-pointers

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.