Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Can function calls in C language be nested?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report