wps宏的功能_宏与功能之间的区别

wps宏的功能

In this post, we are going to understand difference between macro and function. But before getting started, I want to explain little bit about macro and function to you in an easy way.

在本文中,我们将了解宏和函数之间的区别。 但是在开始之前,我想向您简单介绍一些宏和功能。

What is a function?

什么是功能?

A function can be stated as a group of statements that performs some kind of task. In every C program, you’ll notice at least one function that is main() function. The execution of the program starts from there only. You can divide your code into smaller functions for reducing the size of the body of main() function.

可以将函数声明为执行某种任务的一组语句。 在每个C程序中,您都会注意到至少一个函数是main()函数。 程序仅从此处开始执行。 您可以将代码分成较小的函数,以减小main()函数主体的大小。

Now let us see the syntax of a function.

现在让我们看一下函数的语法。

return_type function_name(parameter){
    //body of the function
}

What is a macro?

什么是宏?

Macros are used to define symbolic constants. It is a preprocessor directive, which means it replaces itself with the value which is given to it. Let us understand it with an example.

宏用于定义符号常量。 这是一个预处理程序指令,这意味着它将用为其赋予的值替换自身。 让我们通过一个例子来理解它。

#include <stdio.h>
#define X 3     //macro definition
 
int main(){
    int x = 10;
    printf("%d\n", x + X);    //here the value of 'X' gets replaced by '3' 
}

The output of the above code is:

上面代码的输出是:

13

Hope you’ve got an idea of macro and its use.

希望您对宏及其用法有所了解。

宏与功能之间的区别 (Difference between Macro and Function)

MacroFunction
It is not compiled, it is pre-processed.It is not pre-processed but it is compiled.
Macros do not check for compilation error which leads to unexpected output.Function checks for compilation error and there is a less chance of unexpected output.
Code length is increased.Code length remains same.
Macros are faster in execution than function.Functions are bit slower in execution.
Before compilation process the macro name is replaced by the macro value.In a function call, transfer of control takes place.
Macros are useful when a small piece of code used multiple times in a program.Functions are helpful when a large piece of code repeated number of times.
巨集 功能
它没有编译,而是经过预处理的。 它未经预处理,但已编译。
宏不检查编译错误,这会导致意外输出。 函数检查编译错误,并减少意外输出的机会。
代码长度增加。 代码长度保持不变。
宏在执行方面比函数要快。 函数的执行速度较慢。
在编译过程之前,宏名称将替换为宏值。 在函数调用中,发生控制转移。
当一小段代码在程序中多次使用时,宏很有用。 当一大段代码重复多次时,函数很有用。

Comment below if you have queries regarding above tutorial for difference between macro and function.

如果您对以上教程有疑问,请参见下面的注释,以了解宏和函数之间的区别。

翻译自: https://www.thecrazyprogrammer.com/2018/03/difference-between-macro-and-function.html

wps宏的功能

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值