C-language pointers

Source: Internet
Author: User

pointers are very important data types in C , so what is a pointer?

A pointer type is a variable used to hold the address of a variable, pointing to a variable.

General form of the pointer:* pointer variable name

int *p;

float *P1;

"*" is used to indicate that the variable is a pointer variable, and the preceding type identifier indicates the type of the variable being pointed to

Define an integer variable A and initialize it to 10

int a = 10;

Defines a pointer variable p, which can point to an int's address

int *p;

Assigns the address of variable A to the pointer variable p, so the pointer variable p points to the variable a
p = &a;//& can get the address of a variable in memory

Error instance:

int *g;

g = 20;

The value of a pointer variable is generally not directly assigned to an integer, but instead is assigned by a variable address, as follows:

*p = 20;

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

Void *p3;//This is called an untyped pointer, meaning this is just a pointer variable that does not point to any specific data type, but can be converted to a different type pointer by a forced conversion, or you can use (void *) to convert other type pointers to void type pointers

Null pointer: The value of the pointer is null

C-language 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.