当前位置:网站首页>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 .
边栏推荐
- 2022 question bank and answers for operation certificate examination of safety production management personnel in road transport enterprises
- Clause 34: lambda is preferred over std:: bind
- Little C's Notepad
- Advantages of win8.1 and win10
- Draw a hammer
- Gradient descent, learning rate
- Bomb disposal cat
- Win8.1和Win10各自的優勢
- CMB's written test -- data analysis
- Test question bank and online simulation test for special operation certificate of construction scaffolder (special type of construction work) in 2022
猜你喜欢

Several methods of identifying equivalent circuit of circuit drawing

Chapter 15 mechanism: Address Translation

PostgreSQL Guide: Insider exploration (Chapter 7 heap tuples and index only scanning) - Notes

Embedded hardware: electronic components (1) resistance capacitance inductance

Sampo Lock

How to use redis

Converting MySQL data to PostgreSQL with Navicat

Chapter 18 pagination: Introduction

Win8.1和Win10各自的优势

Solution to sudden font change in word document editing
随机推荐
利用Javeswingjdbc基於mvc設計系統
135. distribute candy
Elliptic curve encryption
Force deduction 121 questions
Advanced C language - Section 1 - data storage
JS to realize the conversion between string and array and an interview question
Section 2 - branch and loop statements
Article 29: assuming that the mobile operation does not exist, is expensive, and is not used
Vercel uses HTTP caching
Autumn wind, dust, youth
rainbow
String()和toString()方法得区别
Avantages de win8.1 et win10
利用Javeswingjdbc基于mvc设计系统
Differences between string() and tostring() methods
Mind mapping series - Database
Article 49: understanding the behavior of new handler
Section 7 - structures
[untitled]
QT direction key to move focus