C Language Learning Seventh chapter

Source: Internet
Author: User

Today began to learn pointers, pointers in C language has a very important position, according to the teacher said, learning C is not good pointers and not learning, the visible pointer in the C language of the important position. Don't say much, first we need to know what is a pointer.

Pointer: A pointer is a variable that stores the memory address of another object, and if one variable stores the address of another object, the variable is said to point to the object.

In other words pointers are also variables, except that, unlike normal variables, stored in memory by another object is stored within the pointer. The value inside the pointer is a hexadecimal value.

Because pointer values are data, pointer variables can be assigned values, so a pointer to the point can be changed in the execution of the program. The pointer p points to the variable x at some point in execution, and to the variable y at another point

1. The format of the definition

L Data Type * pointer variable name ;

L int *p;

2. Define the Post assignment first

L Simple Value

int a = 10;

int *p;

p = &a; [A1]

printf ("%d", *p[a2]);

int nums[10];

P=nums;

L Simple Change value

*p = 9;

3. Assigning values at the same time as defined

int a = 10;

int *p = &a;

4. Attention Points

l int *p; p = 1000;

l int *p; *p = 100;

l int *p; *p = &a;

L &P The address value stored in the output pointer

L Other pointer type description, such as float *p; Char *p;

The type cannot be used indiscriminately, such as int a = 10; float *p = &a;

[A1] Assigns a value to the pointer, the right side of the assignment operator must be an address, if it is a normal variable needs to be preceded by an address operator &; if it is another pointer variable or an array, do not need to add the & operator

    • The [A2] operator * is used to return the value stored in the memory address pointed to by the pointer

C Language Learning Seventh chapter

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.