当前位置:网站首页>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 .
边栏推荐
- 类的基础语法
- 在写web项目的时候,文件上传用到了smartupload,用了new string()进行转码,但是在数据库中,还是会出现类似扑克的乱码
- [文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN
- [untitled] 2022 safety production supervisor examination question bank and simulated safety production supervisor examination questions
- Interface in TS
- 竞品分析撰写
- "Final review" 16/32-bit microprocessor (8086) basic register
- MySQL timestampdiff interval
- 有监督预训练!文本生成又一探索!
- vulnhub HA: Natraj
猜你喜欢
leetcode:297. 二叉树的序列化与反序列化
[home push IMessage] software installation virtual host rental tothebuddy delay
[literature reading] sparse in deep learning: practicing and growth for effective information and training in NN
深潜Kotlin协程(十九):Flow 概述
js实现在可视区内,文字图片动画效果
Two points -leetcode-540 A single element in an ordered array
国产PC系统完成闭环,替代美国软硬件体系的时刻已经到来
Interaction free shell programming
【刷题篇】接雨水(一维)
The 10th China Cloud Computing Conference · China Station: looking forward to the trend of science and technology in the next decade
随机推荐
Social phobia of contemporary young people (III)
解决bp中文乱码
sklearn数据预处理
Leecode swipe questions and record LCP 18 breakfast combination
Interface embedded in golang struct
Basic MySQL operations
eth入门之DAPP
ZIP文件的导出
Square root of X
Supervised pre training! Another exploration of text generation!
[Blue Bridge Road -- bug free code] DS18B20 temperature reading code analysis
Design and implementation of kubelet garbage collection mechanism to protect nodes from being preempted by containers image GC high threshold
[brush questions] connected with rainwater (one dimension)
会员积分商城系统的功能介绍
树莓派如何连接WiFi
300+篇文献!一文详解基于Transformer的多模态学习最新进展
Export of zip file
[no title] 2022 chlorination process examination content and free chlorination process examination questions
竞品分析撰写
[set theory] set concept and relationship (set family | set family examples | multiple sets)