当前位置:网站首页>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
边栏推荐
- 有监督预训练!文本生成又一探索!
- [brush questions] most elements (super water king problem)
- Interface in TS
- 540. Single element in ordered array
- JS realizes lazy loading of pictures
- Which Bluetooth headset is cost-effective? Four Bluetooth headsets with high cost performance are recommended
- [fairseq] 报错:TypeError: _broadcast_coalesced(): incompatible function arguments
- 【毕业季·进击的技术er】职场人的自白
- [Blue Bridge Road -- bug free code] DS18B20 temperature reading code analysis
- JS native common knowledge
猜你喜欢

Dismantle a 100000 yuan BYD "Yuan". Come and see what components are in it.

Supervised pre training! Another exploration of text generation!

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 =

Feature_selection

Mutex and rwmutex in golang

leetcode:297. 二叉树的序列化与反序列化

Application of I2C protocol of STM32F103 (read and write EEPROM)

2022deepbrainchain biweekly report no. 104 (01.16-02.15)

Two points -leetcode-540 A single element in an ordered array

IPv6 foundation construction experiment
随机推荐
Sklearn data preprocessing
[dynamic programming] subsequence problem
Five elements of user experience
[mathematical logic] predicate logic (predicate logic basic equivalent | eliminate quantifier equivalent | quantifier negative equivalent | quantifier scope contraction expansion equivalent | quantifi
QSAR model establishment script based on pytoch and rdkit
DAPP for getting started with eth
[set theory] set concept and relationship (true subset | empty set | complete set | power set | number of set elements | power set steps)
Data Lake three swordsmen -- comparative analysis of delta, Hudi and iceberg
树莓派如何连接WiFi
深潜Kotlin协程(十九):Flow 概述
Mila、渥太华大学 | 用SE(3)不变去噪距离匹配进行分子几何预训练
Appium automated testing framework
[Blue Bridge Road -- bug free code] interpretation of some codes of matrix keyboard
国产PC系统完成闭环,替代美国软硬件体系的时刻已经到来
MPLS setup experiment
有监督预训练!文本生成又一探索!
Two points -leetcode-540 A single element in an ordered array
Analysis of the reason why the server cannot connect remotely
Nat. Comm. | 使用Tensor-cell2cell对细胞通讯进行环境感知去卷积
重绘和回流