Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Can function calls in C language be nested?

Shulou Source: shulou.com Published: 2022-06-02 15:09:21 10月01日 Update

This article mainly introduces whether the function calls in C language can be nested, the article is very detailed, has a certain reference value, interested friends must read it!

Function calls can be nested, but function definitions can not be nested, because the definitions of functions in C language are parallel and independent of each other, that is to say, when defining a function, the function body cannot contain the definition of another function, that is, functions can not be nested definitions, but can be nested calls.

In C language, function calls can be nested, but function definitions cannot be nested.

Cannot nest a definition that is

Function a () {function b () {}}

It is wrong to define a b function in a function. You can only define a b function outside a function like this.

Function a () {} function b () {}

Can be nested calls, that is,

Function a () {b ();}

You can call the defined b function in the a function.

The function cannot be nested because the syntax is not supported so that the function cannot be defined inside the function definition. The definitions of functions in C language are parallel and independent of each other, that is to say, in the definition of functions, the body of functions can not contain the definition of another function, that is, functions can not be nested definitions, but can be nested calls.

What is a nested call to a function?

The process of calling another function in the process of calling one function

Function in C language, the definition of each function is relatively independent, and other functions can be called inside the function (excluding the main () function). This calling process is called nesting of functions (the definition part of a function cannot be nested).

Example:

Find the maximum common divisor and the least common multiple of two integers.

Analysis of problems

The least common multiple of two numbers = the product of two numbers / the maximum common divisor of two numbers.

So key is the greatest common divisor.

The mind map of finding the maximum common divisor:

Code implementation

# define _ CRT_SECURE_NO_WARNINGS 1#include "stdio.h" # include "math.h" int gcd (int a, int b) {int citterif (a)

Tags: Function language maximum two common divisor maximum common divisor minimum common multiple least common multiple procedure independence that is content integer article parallel product code value Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Linux Huawei NVidia Shulou Tech Info