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

How to understand pointer types in C language

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

Share

Shulou(Shulou.com)06/03 Report--

How to understand the pointer type in C language, many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.

0. problem

Zhihu answered a fan question.

As a result, the brother asked a few more questions:

All right, help others to the end, send the Buddha to the west! Let me tell you something thoroughly.

1. Int va

This is an integer variable, 32-bit CPU, 32 bite

2. Int * va

This is an integer pointer variable that is used to store the address of an integer variable

3. Int * * va

This is a second-level pointer of an integer, which is used to store an address of memory, and the address of another integer variable is stored in the memory of that address.

For example:

Int va=0x12345678; int * pva = & va; int * * ppva = & pva

4. Int * va [3]

This is an array whose members are integer pointers to int memory.

5. Int (* va) [3]

This is a pointer to an int array

Note that the address type is int [3] and its value is 0x40004000

Symbols with a value of 0x40004000 include:

A & a [0]

But their type is different from that of va.

6. Void va (int)

This is a function.

The argument to the function is int

The return value is void *

Void (* va) (int) this is a pointer to a function

The function parameter is int

The return value is void

Give an example

Void (* va) (int); void func (int num) {printf ("one Linux% d\ n", num);} va = func; / / call main () {(* va) (6);}

Note: the function name is also an address

8. Int (* va [3]) (int)

Combination mode:

Va is first combined with [3] to show that va is an array.

Va [3] is combined with the outside *, so the array element is a pointer

Suppose (* va [3]) is X with int (X) (int) on the outside, so the pointer points to the function

The formal parameter of the function is int, and the return value is int

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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

Development

Wechat

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

12
Report