int *a[4]; //指针数组
A pointer array is equivalent to declaring multiple pointers at once. Each element of the array is a pointer. It's easy to understand. Let's mainly look at array pointers
int (*p)[4]; //数组指针
Array pointers are equivalent to declaring one pointer at a time. It's just that this pointer points to a very special array.
[] has a priority greater than *, so () must be added when declaring the array pointer.
Example 1:
#include<stdio.h>#include<stdlib.h>void main() { //数组指针的用法,用处。 int b[16]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; int (*p)[4]; //该语句是定义一个数组指针,指针步长为4个int即16位。 //int *p2=&b; p=&b; int i=0; while(i<16) { printf("%d\t",(*p)[i]); //printf("%d\t",*p2++); i++; } }
printf("%d\t",(*p)[i]);Traverse the output array b;
The array pointer is equivalent to The same as King of Dance Zombie, with a younger brother, n is the number of younger brothers. Through the subscript value, you can directly access the specific younger brother, that is, which number in the array.
The array pointer subscript increases automatically (i), the pointer points unchanged.
This can be implemented directly using integer pointers, and it is more convenient and concise. See commented section above.
Example 2: Replace the while() statement in Example 1.
while(i<4) { printf("%d\t",(*p++)[0]); i++; }
Example 2 outputs 1 5 9 13, which is equivalent to the pointer moving 4 int.16 bytes at a time.
When the array pointer is incremented (*p), the pointer points to move sizeof (type).
In fact, the above sentence also applies to other types of pointers.
Such as int *p;
//The pointer points to int, which is an integer pointer. What are the characteristics of integer pointers? It is the address that can save the integer variable. What's the use? That is, p can point to the next int type number. So? Often pointers are used to point to an array. Because they are all of type int, the step size is derived? The step size of the integer pointer is sizeof(int), which is 4 bytes.
//Similarly, we can get float pointers, char pointers, etc. . .
In the same way, we can get the array pointer, what are its characteristics? Save the first address of the array. use? p can point to the next array. So? Use it to point to a two-dimensional array. Because each element in the two-dimensional array is of the same type (all are an int array), can the step size be deduced? sizeof(int[4]), that is, 16
//To put it bluntly, it is a pointer, pointing to the array type
Example 3: The array pointer points to a two-dimensional array.
#include<stdio.h>#include<stdlib.h>void main() { int a[3][4]={{1,2,3,4},{11,12,13,14},{21,22,23,24}}; int (*p)[4]; //该语句是定义一个数组指针,指针步长为4个int即16位。 p=&a; int i=0; while(i<3) { //printf("%d\t",(*p)[i]); //数组指针,指向的是一个数组整体,相当于指针也带了下标,当执行i++操作时,下标+1,得到该数组的下一个元素, //在该例中,指针没有位移,所以依次输出为1 2 3 printf("%d\t",(*p++)[0]); //整型数组类型的指针,指向的是一个数组整体,当执行*p++操作时,指针位移该数组长度的位数 //在该例中,即指针位移4个int的长度,所以输出是1 11 21 i++; } }
Recommended tutorial: "C Video Tutorial"
The above is the detailed content of What are the uses of array pointers?. For more information, please follow other related articles on the PHP Chinese website!

C#.NET is still important because it provides powerful tools and libraries that support multiple application development. 1) C# combines .NET framework to make development efficient and convenient. 2) C#'s type safety and garbage collection mechanism enhance its advantages. 3) .NET provides a cross-platform running environment and rich APIs, improving development flexibility.

C#.NETisversatileforbothwebanddesktopdevelopment.1)Forweb,useASP.NETfordynamicapplications.2)Fordesktop,employWindowsFormsorWPFforrichinterfaces.3)UseXamarinforcross-platformdevelopment,enablingcodesharingacrossWindows,macOS,Linux,andmobiledevices.

C# and .NET adapt to the needs of emerging technologies through continuous updates and optimizations. 1) C# 9.0 and .NET5 introduce record type and performance optimization. 2) .NETCore enhances cloud native and containerized support. 3) ASP.NETCore integrates with modern web technologies. 4) ML.NET supports machine learning and artificial intelligence. 5) Asynchronous programming and best practices improve performance.

C#.NETissuitableforenterprise-levelapplicationswithintheMicrosoftecosystemduetoitsstrongtyping,richlibraries,androbustperformance.However,itmaynotbeidealforcross-platformdevelopmentorwhenrawspeediscritical,wherelanguageslikeRustorGomightbepreferable.

The programming process of C# in .NET includes the following steps: 1) writing C# code, 2) compiling into an intermediate language (IL), and 3) executing by the .NET runtime (CLR). The advantages of C# in .NET are its modern syntax, powerful type system and tight integration with the .NET framework, suitable for various development scenarios from desktop applications to web services.

C# is a modern, object-oriented programming language developed by Microsoft and as part of the .NET framework. 1.C# supports object-oriented programming (OOP), including encapsulation, inheritance and polymorphism. 2. Asynchronous programming in C# is implemented through async and await keywords to improve application responsiveness. 3. Use LINQ to process data collections concisely. 4. Common errors include null reference exceptions and index out-of-range exceptions. Debugging skills include using a debugger and exception handling. 5. Performance optimization includes using StringBuilder and avoiding unnecessary packing and unboxing.

Testing strategies for C#.NET applications include unit testing, integration testing, and end-to-end testing. 1. Unit testing ensures that the minimum unit of the code works independently, using the MSTest, NUnit or xUnit framework. 2. Integrated tests verify the functions of multiple units combined, commonly used simulated data and external services. 3. End-to-end testing simulates the user's complete operation process, and Selenium is usually used for automated testing.

Interview with C# senior developer requires mastering core knowledge such as asynchronous programming, LINQ, and internal working principles of .NET frameworks. 1. Asynchronous programming simplifies operations through async and await to improve application responsiveness. 2.LINQ operates data in SQL style and pay attention to performance. 3. The CLR of the NET framework manages memory, and garbage collection needs to be used with caution.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.