Experiment seven--function definition and invocation summary

Source: Internet
Author: User

1. The knowledge points learned in this lesson:

(1) Any C program execution, starting from the main function main (), if you encounter a function call, the main function is suspended execution, instead of executing the corresponding function, the function will return to the main function after execution, and then continue to execute from the original paused position.

(2) The parameter of the function must be a variable to accept the letter passed by the argument, and the argument can be a constant, a variable, or an expression, which is to pass a constant, variable, or expression to the parameter.

(3) The formal parameter and the argument one by one correspond. The numbers should be the same, the order should be the same, the recommended type is also consistent when beginners.

2. Problems encountered during the experiment and solutions:

(1) The function cannot be brought into the question.

(2) know the meaning of the topic is not very likely to be expressed in a function

(3) Search the book by reading the examples or find solutions on the Internet

3. Experience of experiment and summary of the study in this chapter:

(1) The function declaration is a C statement, and the function definition is not the first statement, and cannot be followed by a semicolon

(2) Formal parameter list cannot be written as double R, H

(3) void cannot be omitted in a function definition that does not return a result; otherwise, the function type is defined by default as int

4. Preview

When defining the pyramid () function, omitting the return statement does not mean that the function cannot be returned. For a function of type void, if the return statement is omitted, when all the statements in the function have been executed, the last curly brace is returned to the main function automatically.

Additional Question 3

#include <stdio.h>

int main (void)

{

int n,count,sum,tmp;

printf ("Input an Integer:");

while (scanf ("%d", &n)!=eof&&n>=0)

{

Count=1;

Sum=o;

while (n>0)

{

tmp=n%10;

sum+=tmp;

N=N/10;

if (n>0)

{

count++;

}

}

printf ("count=%d,sum=%d\n", count,sum);

printf ("Input an Integer:");

}

return 0;

}

Experiment seven--function definition and invocation summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.