Computer Science, asked by navyasrivarma082, 7 months ago

differentiate between a macro and a function?​

Answers

Answered by fafreen431
0

Explanation:

functions means

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.

macro means

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.

differentiate between them

Macro Function

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

Answered by varikupalakrishna198
1

Explanation:

Macro

* code length is increased.

* Macro are faster in execution than function.

* Before compilation process the macro name is replaced by the macro value.

Function

* code length remains same.

* Functions are bit of slower in execution.

* In a function call, transfer for control takes place.

Similar questions