Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example Analysis of C language pointer

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "C language pointer example analysis". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn "c language pointer example analysis" it!

A pointer to a pointer.

A pointer can point to an integer variable, a character variable, or a pointer variable.

Use one pointer variable A to store the address of another pointer variable, and call the pointer variable A the pointer variable pointing to the pointer.

Pointer variable definition form that points to the pointer:

Type specifier * * pointer variable name

For example: int * * p

Pointer variables as function parameters

The parameter type of a function can be any legal C language type.

Pointer variables can also be used as function arguments.

(1) Exchange of integer variables with formal parameters

(2) the exchange of formal parameters as pointer variables

(3) the data transfer between arguments and formal parameters in C language is an one-way "value transfer" mode, and the same is true when pointer variables are used as function parameters. It is impossible to change the value of the parameter pointer variable by changing the value of the parameter pointer variable in the called function, but the value of the parameter pointer variable can be changed indirectly by changing the value pointed to by the parameter pointer variable.

Functions that return pointers and pointers to functions

The function return value can be any legal C language data type, so the function return value can also be a pointer type.

Type specifier * function name (parameter list)

For example:

Int * fun (int x, int y)

In addition to functions that return pointers, there are pointers to functions.

When a function is compiled, it is assigned an entry address, which is called the address of the function. The function address is assigned to a function pointer variable, which can point to the function.

Define the form:

Type descriptor (* pointer name) (parameter list)

For example:

Int func (int x, int y)

Int (* p) (int x, int y); / * p is the function pointer * /

P = func; / * function pointer p points to function func () * /

Call method:

Function pointer name (argument list)

For example: P (x, y); equivalent to func (x, y)

Note:

(1) A function pointer is defined, and a function address needs to be assigned to the function pointer before the function can be called through the function pointer.

(2) when assigning a function address to a function pointer, the characteristic of the function must be the same as when the function pointer is defined, otherwise there is an error in compilation. The function feature refers to the number, type and return value type of the function's parameter list.

At this point, I believe that everyone has a deeper understanding of the "c language pointer example analysis", might as well come to the actual operation! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report