C language pointer, C language pointer

Source: Internet
Author: User

C language pointer, C language pointer

Pointers are very important data types in C language. What are pointers?

The pointer type is a variable used to store the variable address, pointing to a variable.

Common pointer format: * pointer variable name

Int * p;

Float * p1;

"*" Is used to indicate that this variable is a pointer variable. The previous type identifier indicates the type pointing to the variable.

// Define an integer variable a and initialize it to 10

Int a = 10;

// Define a pointer Variable p that can point to the int address

Int * p;

// Assign the address of variable a to the pointer Variable p, so the pointer Variable p points to variable
P = & a; // you can obtain the address of a variable in the memory.

Error instance:

Int * g;

G = 20;

Generally, the value of a pointer variable cannot be directly assigned an integer, but is assigned by the variable address, as shown below:

* P = 20;

Printf ("a = % d \ n", );

Void * p3; // This is called a non-type pointer, which means this is only a pointer variable and does not point to any specific data type, however, you can convert void * to another type pointer by force conversion, or convert other types of pointer to void type pointer by using (void *).

NULL Pointer: the pointer value is NULL.

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.