当前位置:网站首页>Make learning pointer easier (3)
Make learning pointer easier (3)
2022-07-06 07:58:00 【Xiao Zhang, China Academy of Aeronautical Sciences】
List of articles
Preface
Pointer interview questions , The understanding of pointer no longer stays at the simple level of knowledge , Instead, you can know how the pointer in the interview question is examined ;
One 、 Pointer and array written test question analysis
1.1 One dimensional array
First, let's talk about the knowledge points : Very important !!!
The meaning of array names :
- sizeof( Array name ), The array name here represents the entire array , It calculates the size of the entire array .
- & Array name , The array name here represents the entire array , It takes out the address of the entire array .
- In addition, all array names represent the address of the first element .
int a[ ] = {1,2,3,4};
printf( “%d\n”,sizeof(a) );
printf( “%d\n”,sizeof(a+0) );
printf( “%d\n”,sizeof(a) );
printf( “%d\n”,sizeof(a+1) );
printf( “%d\n”,sizeof(a[1]) );
printf( “%d\n”,sizeof(&a) );
printf( “%d\n”,sizeof(&a) ;
printf( “%d\n”,sizeof(&a+1) );
printf( “%d\n”,sizeof(&a[0]) );
printf( “%d\n”,sizeof(&a[0]+1) );
1.2 A character array
char arr[] = {‘a’,‘b’,‘c’,‘d’,‘e’,‘f’};
printf(“%d\n”, sizeof(arr));
printf(“%d\n”, sizeof(arr+0));
printf(“%d\n”, sizeof(*arr));
printf(“%d\n”, sizeof(arr[1]));
printf(“%d\n”, sizeof(&arr));
printf(“%d\n”, sizeof(&arr+1));
printf(“%d\n”, sizeof(&arr[0]+1));
printf(“%d\n”, strlen(arr));
printf(“%d\n”, strlen(arr+0));
printf(“%d\n”, strlen(*arr));
printf(“%d\n”, strlen(arr[1]));
printf(“%d\n”, strlen(&arr));
printf(“%d\n”, strlen(&arr+1));
printf(“%d\n”, strlen(&arr[0]+1));
char arr[] = “abcdef”;
printf(“%d\n”, sizeof(arr));
printf(“%d\n”, sizeof(arr+0));
printf(“%d\n”, sizeof(*arr));
printf(“%d\n”, sizeof(arr[1]));
printf(“%d\n”, sizeof(&arr));
printf(“%d\n”, sizeof(&arr+1));
printf(“%d\n”, sizeof(&arr[0]+1));
printf(“%d\n”, strlen(arr));
printf(“%d\n”, strlen(arr+0));
printf(“%d\n”, strlen(*arr));
printf(“%d\n”, strlen(arr[1]));
printf(“%d\n”, strlen(&arr));
printf(“%d\n”, strlen(&arr+1));
printf(“%d\n”, strlen(&arr[0]+1));
char *p = “abcdef”;
printf(“%d\n”, sizeof§);
printf(“%d\n”, sizeof(p+1));
printf(“%d\n”, sizeof(*p));
printf(“%d\n”, sizeof(p[0]));
printf(“%d\n”, sizeof(&p));
printf(“%d\n”, sizeof(&p+1));
printf(“%d\n”, sizeof(&p[0]+1));
printf(“%d\n”, strlen§);
printf(“%d\n”, strlen(p+1));
printf(“%d\n”, strlen(*p));
printf(“%d\n”, strlen(p[0]));
printf(“%d\n”, strlen(&p));
printf(“%d\n”, strlen(&p+1));
printf(“%d\n”, strlen(&p[0]+1));
1.3 Two dimensional array
int a[3][4] = {0};
printf( “%d\n”,sizeof(a) );
printf( “%d\n",sizeof(a[0][0]) );
printf( “%d\n”,sizeof(a[0]) );
printf( ”%d\n",sizeof(a[0]+1) );
printf( “%d\n”,sizeof(* (a[0]+1)) );
printf( “%d\n”,sizeof(a+1) );
printf( “%d\n”,sizeof(* ( a+1) ) );
printf( “%d\n”,sizeof(&a[0]+1) );
printf( “%d\n”,sizeof( * (&a[0]+1) ) );
printf( “%d\n”,sizeof(*a) );
printf( “%d\n”,sizeof(a[3]) );
2. Pointer written test questions
int main()
{
int a[5] = { 1, 2, 3, 4, 5 };
int *ptr = (int *)(&a + 1);
printf( “%d,%d”, *(a + 1), *(ptr - 1));
return 0;
}
// What is the result of the program ?
// Because I haven't learned the structure yet , The size of the structure is 20 Bytes
struct Test
{
int Num;
char *pcName;
short sDate;
char cha[2];
short sBa[4];
}*p;
// hypothesis p The value of is 0x100000. What are the values of the expressions in the following table ?
// It is known that , Structure Test The variable size of type is 20 Bytes
int main()
{
printf(“%p\n”, p + 0x1);
printf(“%p\n”, ( unsigned long )p + 0x1);
printf(“%p\n”, (unsigned int * )p + 0x1);
return 0;
}
int main()
{
int a[4] = { 1, 2, 3, 4 };
int *ptr1 = (int *)(&a + 1);
int *ptr2 = (int *)((int)a + 1);
printf( “%x,%x”, ptr1[-1], *ptr2);
return 0;
}
#include <stdio.h>
int main()
{
int a[3][2] = { (0, 1), (2, 3), (4, 5) };
int *p;
p = a[0];
printf( “%d”, p[0]);
return 0;
}
int main()
{
int a[5][5];
int(*p)[4];
p = a;
printf( “%p,%d\n”, &p[4][2] - &a[4][2], &p[4][2] - &a[4][2]);
return 0;
}
int main()
{
int aa[2][5] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int *ptr1 = (int *)(&aa + 1);
int *ptr2 = (int * )( * (aa + 1) );
printf( “%d,%d”, * (ptr1 - 1), *(ptr2 - 1) );
return 0;
}
#include <stdio.h>
int main()
{
char *a[] = {“work”,“at”,“alibaba”};
char**pa = a;
pa++;
printf(“%s\n”, *pa);
return 0;
}
int main()
{
char * c[ ] = {“ENTER”,“NEW”,“POINT”,“FIRST”};
char ** cp[] = {c+3,c+2,c+1,c};
char *** cpp = cp;
printf(“%s\n”, ** ++cpp);
printf(“%s\n”, * --* ++cpp+3);
printf(“%s\n”, * cpp[-2]+3);
printf(“%s\n”, cpp[-1][-1]+1);
return 0;
}
summary
Pointer's blog is over , Please look forward to the next blog !!!
边栏推荐
- MySQL view tablespace and create table statements
- Luogu p1836 number page solution
- Simulation of Teman green interferometer based on MATLAB
- Simulation of Michelson interferometer based on MATLAB
- 861. Score after flipping the matrix
- [t31zl intelligent video application processor data]
- Database addition, deletion, modification and query
- Data governance: data quality
- TS 体操 &(交叉运算) 和 接口的继承的区别
- Apache middleware vulnerability recurrence
猜你喜欢
Parameter self-tuning of relay feedback PID controller
. Net 6 learning notes: what is NET Core
Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
成为优秀的TS体操高手 之 TS 类型体操前置知识储备
Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
数据治理:主数据的3特征、4超越和3二八原则
Nft智能合约发行,盲盒,公开发售技术实战--拼图篇
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Mex related learning
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
随机推荐
MES, APS and ERP are essential to realize fine production
Simulation of holographic interferogram and phase reconstruction of Fourier transform based on MATLAB
Luogu p1836 number page solution
Data governance: metadata management
实现精细化生产, MES、APS、ERP必不可少
Asia Pacific Financial Media | art cube of "designer universe": Guangzhou community designers achieve "great improvement" in urban quality | observation of stable strategy industry fund
File upload of DVWA range
In the era of digital economy, how to ensure security?
[1. Delphi foundation] 1 Introduction to Delphi Programming
How to prevent Association in cross-border e-commerce multi account operations?
让学指针变得更简单(三)
[非线性控制理论]9_非线性控制理论串讲
继电反馈PID控制器参数自整定
"Designer universe": "benefit dimension" APEC public welfare + 2022 the latest slogan and the new platform will be launched soon | Asia Pacific Financial Media
Onie supports pice hard disk
Redis list detailed explanation of character types yyds dry goods inventory
TS 类型体操 之 extends,Equal,Alike 使用场景和实现对比
Data governance: misunderstanding sorting
Launch APS system to break the problem of decoupling material procurement plan from production practice
TS 体操 &(交叉运算) 和 接口的继承的区别