当前位置:网站首页>Preliminary cognition of C language pointer
Preliminary cognition of C language pointer
2022-07-03 04:17:00 【*(*(arr+i)+j)】
1 How variables are accessed
2 The definition of a pointer variable
3 actual combat
1 Two ways to access variables :1 By variable name 2 adopt Variable address Let's give you an example
such as xx The flower shop Where are you going You need to know the name of the florist perhaps yes The address of the florist such You can get to .
Two ways to access variables Code It's a demonstration
#include<stdio.h>
void main(void)
{
int a=10;
printf("%d\n",a);// Access... By variable name
printf("%d\n",*(&a));// Access by address
}
#include<stdio.h> Header file means Include input and output functions in a specific path
Direct use a Namely Variable name visit perhaps Take the address of the variable name stay * Is to take out the value of the address These are two ways to access variables The end result is the same .
2 Pointer variable meaning : A variable that holds the address The pointer Address again So simply understand The pointer == Address Address == The pointer
The definition of a pointer variable
int *p;
Define a int Pointer variable of type * Is an ID And tell the computer to declare that I am a pointer variable
Application of pointer variables
#include<stdio.h>
void main(void)
{
int a=10; // Define a int Type of a Variable
int *p;// Define a pointer variable * Is an identifier. Tell the computer to declare that I am a pointer variable
p=&a;// initialization
printf(" The value obtained by accessing the address :%d",*p);// How to write it 1
printf(" It is also the value obtained through address access :%d",*(&a));// And writing 1 equally
printf(" Value obtained by variable name %d",a);
}
Pointer variables need Type required We illustrate with several examples
First Let's define a char Pointer to type Variable and int Variable of type size use sizeof keyword Print out
See how it turns out
#include<stdio.h>
void main(void)
{
int *p=10;
char *a=2;
printf("int Pointer variable size of type %d\n",sizeof(*p));
printf("char Pointer variable size of type %d",sizeof(*a));
}
Defined a int Pointer variable of type It's a point int Variable of type char That's the same understanding
So in the printout The result is 4 and 1
int The type is 4 Bytes char yes A byte
We are adopting a method Come on prove Pointer to the variable need Claim type statement
Print by offset Address contrast
#include<stdio.h>
void main(void)
{
int *p;
char *a;
printf("int No offset %#x\n",p);
printf("int With offset %#x\n",++p);
printf("\n");
printf("char type No offset %#x\n",a);
printf("char The type has an offset %#x\n",++a);
}
Running results
Why does this result
1 int The type is Four byte size Self adding offset One is Four bytes
2 char The type is 1 Byte size Self adding The offset One is A byte
The problem of address offset Is it right? The offset of the whole block , Not at all
First use int Examples of types It has a size of four bytes We In operation offset when It is active within its four byte range . Another way int type It's four bytes Offset by one (++p)int The type becomes 8 Bytes Obviously it's not right . It's like A vernier caliper It's so big You can move The offset To different addresses
in general Pointer variables require defined types because It determines 1 Point to the size of the space 2 Determines the offset
int The type remember is Four byte size char The type is a byte size
边栏推荐
- [set theory] set concept and relationship (set represents | number set | set relationship | contains | equality | set relationship property)
- China Mobile Internet of things oneos and onenet were selected in the list of 2021 Internet of things demonstration projects
- 2.14 simulation summary
- Export of zip file
- Social phobia of contemporary young people (II)
- 2022 beautician (intermediate) new version test questions and beautician (intermediate) certificate examination
- 用户体验五要素
- JS realizes the animation effect of text and pictures in the visual area
- Arduino application development - LCD display GIF dynamic diagram
- "Designer universe" argument: Data Optimization in the design field is finally reflected in cost, safety and health | chinabrand.com org
猜你喜欢
[home push IMessage] software installation virtual host rental tothebuddy delay
国产PC系统完成闭环,替代美国软硬件体系的时刻已经到来
JMeter starts from zero (III) -- simple use of regular expressions
Pdf editing tool movavi pdfchef 2022 direct download
Which Bluetooth headset is good about 400? Four Bluetooth headsets with strong noise reduction are recommended
IPv6 foundation construction experiment
"Final review" 16/32-bit microprocessor (8086) basic register
『期末复习』16/32位微处理器(8086)基本寄存器
有监督预训练!文本生成又一探索!
arthas watch 抓取入参的某个字段/属性
随机推荐
Nodejs Foundation: shallow chat URL and querystring module
2022-07-02: what is the output of the following go language code? A: Compilation error; B:Panic; C:NaN。 package main import “fmt“ func main() { var a =
[dynamic programming] subsequence problem
Competitive product analysis and writing
Square root of X
国产PC系统完成闭环,替代美国软硬件体系的时刻已经到来
2022 beautician (intermediate) new version test questions and beautician (intermediate) certificate examination
商城系统搭建完成后需要设置哪些功能
Leecode swipe questions and record LCP 18 breakfast combination
Which code editor is easy to use? Code editing software recommendation
类的基础语法
[brush questions] most elements (super water king problem)
Appium自动化测试框架
GFS分布式文件系统(光是遇见已经很美好了)
Bisher - based on SSM pet adoption center
CVPR 2022 | 大連理工提出自校准照明框架,用於現實場景的微光圖像增强
How to process the current cell with a custom formula in conditional format- How to address the current cell in conditional format custom formula?
Social phobia of contemporary young people (II)
[Apple Push] IMessage group sending condition document (push certificate) development tool pushnotification
[set theory] set concept and relationship (set family | set family examples | multiple sets)