C language pointer advanced-2

This article takes  1.  Array parameter passing and pointer parameter passing 2. Function pointer 3.    The relevant knowledge of function pointer array is explained in detail!

If you think the article is good, I look forward to your one-click triple link. Your encouragement is the source of my creative motivation. Let us work together, run together, and let us meet at the top! ! !


Table of contents

1. Array parameter passing and pointer parameter passing

1. One-dimensional array

2. Two-dimensional array

3. First-level pointer parameter passing

4. Secondary pointer parameter passing

2. Function pointer

1. Necessary knowledge of function pointers

2. Use of function pointers

3. Array of function pointers

1. Introduction to function pointer array

2. Use of function pointer array:


1. Array parameter passing and pointer parameter passing

1. One-dimensional array

For the parameter passing of one-dimensional array, the formal parameter part can be an array or a pointer;

like:

 Note : Although the formal parameter is written in the form of an array, it is actually implemented through a pointer, but the syntax allows it to be written in the form of an array;

2. Two-dimensional array

Two-dimensional array parameter passing, the part of the formal parameter can be an array or a pointer;

3. First-level pointer parameter passing

think:
When the parameter part of a function is a first-level pointer, what parameters can the function receive?
The address of the variable can be passed, or a first-level pointer variable, etc.;

Notice:

When customizing functions, pay attention to whether the formal parameters and actual parameter types can match;

4. Secondary pointer parameter passing

think:
When the parameter of the function is a secondary pointer, what parameters can it receive?

2. Function pointer

1. Necessary knowledge of function pointers

array pointer -- pointer to array

function pointer -- a pointer to a function

Let's look at this code first:

The output is:

in conclusion:

The function name represents the address of the function;

&The function name also represents the address of the first element;

Function pointer variable -- a variable that stores the address of a function

First of all, if the storage address can be given, pfun1 or pfun2 is required to be a pointer, so which one is a pointer?
the answer is:
pfun1 can be stored; pfun1 is first combined with *, indicating that pfun1 is a pointer, and the pointer points to a function, and the pointed function has no parameters
Number, the return value type is void;

2. Use of function pointers

Demonstrate with example:

operation result:

3. Array of function pointers

1. Introduction to function pointer array

An array is a storage space that stores data of the same type

For example int * arr[10]={0};

Then store the address of the function in an array, then this array is called an array of function pointers, how to define the array of function pointers?

the answer is:

parr1 parr1 is first combined with [ ] , indicating that parr1 is an array, what is the content of the array?

is a function pointer of type int (*)() ;

2. Use of function pointer array:

operation result:

end of this chapter~


Guess you like

Origin blog.csdn.net/2301_77509762/article/details/132021837
Recommended