当前位置:网站首页>Introduction of pointer variables in function parameters
Introduction of pointer variables in function parameters
2022-07-03 04:17:00 【*(*(arr+i)+j)】
1 Common function encapsulation calls
2 Introduction of pointer variables
1 Common function encapsulation calls : below Write a piece of code to guess Don't rush to give the answer There will be surprises behind
#include<stdio.h>
// Test whether the size exchange is successful
void Print(int data,int data2)
{
int temp;// Swap size
temp=data;
data=data2;
data2=temp;
}
void main(void)// Define a void Type of Invisible reference main function
{
int data=10;// Define a int Type of data Variable
int data2=11;
Print( data,data2);// Call the wrapper function
printf(" Finally exchange result :%d %d",data,data2);// Print data
}
This code Not much But it's easy to step into a hole I also believe you have the answer
Why? There will be such a phenomenon The function is not called And print 了
because c Language Every time you generate a function A memory address will be generated although Assignment occurred however It didn't work
Because in the main function definition Just print it out Called function Although the value has passed however Do not operate at the same address
therefore Can't Link .
The following is the function to be called Introduce change parameter type That's it Pointer to the variable Define a pointer variable By assignment Store address to pointer variable Swap sizes through function operations
#include<stdio.h>
void Print(int *data,int *data2)
{
int temp;// Swap size
temp=*data;
*data=*data2;
*data2=temp;
}
void main(void)// Define a void Type of Invisible reference main function
{
int data=10;// Define a int Type of data Variable
int data2=11;
Print(&data,&data2);// Call the wrapper function
printf(" Finally exchange result :%d %d",*(&data),*(&data2));// Print data
}
2 Introduction of pointer variables
Let's talk about it first How does he assign a value when calling a function
left arrow It can be written. int*data=&data Initialization and definition are included here It's written separately int *data;data=&data; So simple This is the decomposition of the writing process in which they assign values .
Pointer to the variable Is the variable that stores the address be relative to Pass the address of a main function To pointer variable ; Inside operation It's equivalent to the same address In this way, the number size exchange can be completed .
边栏推荐
- [literature reading] sparse in deep learning: practicing and growth for effective information and training in NN
- Deep dive kotlin synergy (20): build flow
- Xrandr modifier la résolution et le taux de rafraîchissement
- [fairseq] 报错:TypeError: _broadcast_coalesced(): incompatible function arguments
- PostgreSQL database high availability Patroni source code learning - etcd class
- 2.14 simulation summary
- 【毕业季·进击的技术er】职场人的自白
- Social phobia of contemporary young people (III)
- ZIP文件的导出
- Js/ts bottom implementation double click event
猜你喜欢
2022 tea master (intermediate) examination questions and analysis and tea master (intermediate) practical examination video
【刷题篇】接雨水(一维)
BMZCTF simple_ pop
Esp32 series (3): GPIO learning (take simple GPIO input and output, ADC, DAC as examples)
中移物联网OneOS与OneNET入选《2021年物联网示范项目名单》
Feature_selection
跨境电商多商户系统怎么选
Arduino application development - LCD display GIF dynamic diagram
JS native common knowledge
【刷题篇】 找出第 K 小的数对距离
随机推荐
ZIP文件的导出
Export of zip file
CVPR 2022 | Dalian Technology propose un cadre d'éclairage auto - étalonné pour l'amélioration de l'image de faible luminosité de la scène réelle
Deep dive kotlin synergy (19): flow overview
Analysis of the reason why the server cannot connect remotely
vulnhub HA: Natraj
Application of I2C protocol of STM32F103 (read and write EEPROM)
sklearn数据预处理
[Blue Bridge Road -- bug free code] DS18B20 temperature reading code analysis
[no title] 2022 chlorination process examination content and free chlorination process examination questions
JMeter starts from zero (III) -- simple use of regular expressions
CVPR 2022 | Dalian Institute of technology proposes a self calibration lighting framework for low light level image enhancement of real scenes
MySQL create table
[Apple Push] IMessage group sending condition document (push certificate) development tool pushnotification
Xrandr modify resolution and refresh rate
redis 持久化原理
Reflection and planning of a sophomore majoring in electronic information engineering
中移物联网OneOS与OneNET入选《2021年物联网示范项目名单》
"Designer universe" argument: Data Optimization in the design field is finally reflected in cost, safety and health | chinabrand.com org
IPv6 foundation construction experiment