Dark Horse programmer--"Dark Horse video Note"--pointer to C language Foundation

Source: Internet
Author: User

1. Definition of pointers

Format: Variable type * variable name;

   1:  //defines a pointer variable p
   2:      //pointer variable can only store address
   3:      //Pointer is a function: can access the corresponding storage space according to an address value
   4:      //pointer variable p before INT: pointer variable p can only point to data of type int
   5:  
   6:  int *p;

2. Pointers pointing to pointers

3. Pointers and Arrays

1) How array elements are accessed int ages[5];int *p;p = ages;1> array name [subscript] ages[i]2> pointer variable name [subscript] p[i]3> * (P + i) 2) pointer variable +1, address value exactly how much, depending on the type of pointer int * 4 char * 1 double * 8

4. Point of attention of the pointer

1

   1:  /* Not recommended notation, int *p can only point to data of type int
   2:      int *p;
   3:      Double d = 10.0;
   4:      p = &d;*/

2

   1:  /  * Pointer variable can only store address
   2:      int *p;
   3:      p = $;
   4:      * /

3

/* Pointer variable is not initialized, do not use indirect access to other storage spaces
    int *p;
    printf ("%d\n", *p);
    */

4

When defining a variable, the * is only a symbol, no other special meaning
    int *p = &a;

5

    Incorrect wording
    *p = &a;
    p = &a;

6

The function of this time: access to the storage space pointed to by the variable p
    *p = 20;

Dark Horse programmer--"Dark Horse video Note"--pointer to C language Foundation

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.