龙空技术网

C语言(十一):常量指针与函数

LearningYard学苑 233

前言:

现在朋友们对“c语言modify函数”大约比较看重,姐妹们都需要学习一些“c语言modify函数”的相关内容。那么小编在网络上搜集了一些关于“c语言modify函数””的相关知识,希望各位老铁们能喜欢,姐妹们一起来了解一下吧!

分享兴趣,传播快乐,

增长见闻,留下美好!

亲爱的您,这里是LearningYard新学苑。

今天小编为大家带来的是

C语言(十一):常量指针与函数。

Share interests, spread happiness,

increase knowledge, and leave behind beauty!

Dear you, this is the Learning Yard New School.

Today's editor brings you the

C language (11): Constant pointers and functions.

一、思维导图

此推文关于常量指针与函数的内容主要如下:

The main content of this tweet about constant pointers and functions is as follows:

二、常量和指针

(一)、常量

1、520,‘a’,3.14是常量

2、利用宏定义,如#define PRICE 345;

3、const修饰,如const float pi=3.14;

(1)Constants

1、520, ‘a’, 3.14 are constants

2. Use macro definitions such as # define PRICE 345;

3. Const modification, such as const float pi=3.14;

(二)、指向常量的指针

无法直接修改指针的值,但是可以通过修改指针指向的地址或指针指向未被const修饰的变量的值来改变指针的值

(2) Pointer to constant

You cannot directly modify the value of a pointer, but you can change the value of the pointer by modifying the address it points to or the value of a variable that is not modified by const

(三)、常量指针

格式:* const p

指向非常量的常量指针指向的值可以被改变,即*p可变;但是自身的值无法改变,即p不能改变。

指向常量的常量指针指针自身不可被修改,指针指向的值也不可以被修改。

(开发中极少使用,因为当指针指向的是一个变量时,通过修改变量也可以修改指针)

(3)constant pointer

Format: * const p

The value pointed to by a constant pointer to a non-constant quantity can be changed, that is, * p is variable; However, its own value cannot be changed, that is, p cannot be changed.

A constant pointer to a constant cannot itself be modified, nor can the value pointed to by the pointer be modified.

(It is rarely used in development because when a pointer points to a variable, it can also be modified by modifying the variable.)

(四)指向“指向常量的常量指针”的指针

格式:* const *pp

(4) Pointer to "Constant Pointer to Constant"

Format: * const * pp

这里要注意p的地址与p中存放的地址是不同的两个东西

在这里,p中存放的地址为000000000062FE14(P),而p中的地址为000000000062FE08(&p)

Note that the address of p is different from the address stored in p

Here, the address stored in p is 0000000000 62FE14 (P), while the address stored in p is 0000000000 62FE08 (&p)

三、函数

(一)目前我们在开发中遇到的问题

(1) Problems we currently encounter in development

(二)函数的定义

类型名 函数名(参数列表)

{

函数体

}

如果没有参数还是要带上小括号

(2) Definition of functions

Type name Function name (parameter list)

{

Function body

}

If there are no parameters, use parentheses

示例:

give typical examples:

先用函数对代码进行封装再调用

Encapsulate the code with a function before calling it

(三)函数的声明

如上图第三行代码,如果被删除代码仍然可以运行;但是若将函数定义放在后面,老版编译器不能运行,但是有的编译器会执行但会给出提醒

(3) Declaration of functions

As shown in the third line of code above, if the code is deleted, it can still run; "However, if you leave function definitions behind, older compilers cannot run, but some compilers will execute them but give a reminder"

(四)函数的参数和返回值

void类型表示不返回,int类型需要返回

(4) Parameters and return values of functions

The void type indicates no return, while the int type requires a return

示例:

give typical examples:

声明参数的类型和数量一定要写;实参与形参声明变量名可以不同;遇到return语句成立立刻返回,不会执行后面的语句

The type and quantity of declared parameters must be written; The variable names declared by actual parameters and formal parameters can be different; "When a return statement is set, it returns immediately, and subsequent statements will not be executed."

结语:编者认为指针部分比较难懂,所以文章有什么问题还请大家提出来。

Conclusion: The editor thinks that the pointer part is difficult to understand, so if there is any problem in the article, please ask everyone to raise it.

今天的分享就到这里了。

如果您对今天的文章有独特的想法,

欢迎给我们留言,

让我们相约明天,

祝您今天过得开心快乐!

That's all for today's sharing.

If you have unique ideas about today's article,

please leave us a message.

Let's meet tomorrow.

I wish you a happy day!

翻译:百度翻译

参考:《零基础入门学习C语言:带你学C带你飞》、哔哩哔哩小甲鱼视频、网络图片

声明:本文由LearningYard新学苑原创,若有侵权请联系删除

文案&排版:易春秀

审核:闫庆红

标签: #c语言modify函数 #c语言nor #c语言删除程序代码