当前位置:网站首页>C language learning log 1.2
C language learning log 1.2
2022-06-13 04:57:00 【Today is also a day without baldness】
One . Pointer use cases :
(1): Function returns multiple variables , for example :
#include<stdio.h>
void minmax(int a[], int len, int *max,int *min);
int main(void){
int a[] ={1,2,3,4,5,6,7,8,9,10,14,16,17,21,23,66};
int min,max;
minmax(a,sizof(a)/sizof(a[0]),&min,&max);
return 0;
}
void minmax(int a[], int len, int *min, int *max)
{
int i;
*min =*max =a[0];
for(i=1;i<len;i++){
if(a[i] <*min) *min = a[i];
if(a[i] >*max) *max= a[i];
}
}(2) Function returns the operation status , The result returns... Through the pointer , for example :
#include<stdio.h>
int divide(int a,int b,int *result);
int main(void)
{
int a=5,b=2,c;
if(divide(a,b,&c){
printf("%d / %d = %d",a,b,c);
}
return 0;
}
int divide(int a,int b,int *result);
{
int ret=1;
if(b==0){
ret=0;
}else{
*result=a/b;
}
return ret;
}Two . About adding... To a pointer const
Pointer is const: Indicates that once the address of a variable is obtained , Cannot point to other variables .
for example :int *const q=&i; q yes const
Refers to const: Indicates that the variable cannot be modified through this pointer ( It can't be that variable that becomes const)
for example :const int *p =&i; *p Assignment operation is not allowed .
The way of distinction : Judge const stay * Front or back , In the front, it means const, After that, the pointer is const.
Tips:const int a[]={1,2,3,4,5} It means const Array , The array itself is a const The pointer represents a This array cannot point to other arrays , Add another one outside const It means that the value in it cannot be changed , So this kind of array can only be assigned by initialization .
边栏推荐
- C # get all callable methods of WebService interface [webmethod]
- Article 29: assuming that the mobile operation does not exist, is expensive, and is not used
- LeetCode第297场周赛(20220612)
- Design system based on MVC using javeswingjdbc
- Reductive elimination
- 小C的记事本
- 利用Javeswingjdbc基于mvc设计系统
- Section 5 - Operator details
- Sub paragraph of Chapter 16
- Introduction to QT XML
猜你喜欢

2021TPAMI/图像处理:Exploiting Deep Generative Prior for Versatile Image Restoration and Manipulation

Spread your wings and soar

Infinite cycle scrolling code Alibaba international station store decoration code base map scrolling black translucent display effect custom content decoration code full screen display

Kaggle 时间序列教程

QT signal is automatically associated with the slot

Chapter 18 pagination: Introduction

Mysql8.0.13 installation tutorial (with pictures)

Explain the differences and usage scenarios between created and mounted

RMQ、LCA

Regular expressions in QT
随机推荐
General communication protocol for industrial Internet
Section 3 - functions
Win8.1和Win10各自的优势
利用Javeswingjdbc基於mvc設計系統
2022 oxidation process operation certificate examination question bank and simulation examination
Shell built-in string substitution
Createanonymousthreadx passes parameters to anonymous threads
Implementing the driver registration initcall mechanism on stm32
How to handle async/await error messages gracefully
小C的记事本
OpenCV中的saturate操作(饱和操作)究竟是怎么回事
[untitled]
Opencv image storage and reading
Flutter dart variables and constants
Analysis on the similarities and differences of MVC, MVP and mvvc
About mission planning and improving execution
rainbow
String()和toString()方法得区别
QT brushes and brushes
The games that you've tasted