The formal and practical parameters of C language

Source: Internet
Author: User

One-shape participation Argument

1). define

Formal Parameter: Formal Parameters.

When defining a function, the parameter that is written at the back of the Letter's parentheses is called the formal argument

arguments: actual Parameters.

When calling a function, the argument that is written after the Function's parentheses is called the Arguments.

2). Note

A. An argument can be either a constant, a variable, or an expression; a formal parameter: it can actually be understood as a local variable of the Function.

B. Argument-to-parameter values, in fact, is equivalent to assigning a parameter (local Variable) to a function

C. Value passing: changes the value of a parameter within a function without affecting the outside argument

D. in the C language, all types, except arrays, are passed value as argument passing

Two-parameter function

function definition syntax with parameters:

void function name (type parameter Name) {

function body;

}

Application Scenario: When a function has to pass some data to the outside of a function, use parameters

Tips: code examples are as follows

#include <stdio.h>

/*

* Determine if a number is a narcissus number

*/

void Isflower (int Num) {

int Bai = num/100;

int Shi = num/10% 10;

int GE = num% 10;

If hundred * hundred * ten * ten * ten + A * each is equal to this number

If (bai*bai*bai + Shi*shi*shi + Ge*ge*ge = = Num) {

Is the number of daffodils

printf ("%d is the number of daffodils \ n", num);

}else{

otherwise, It's not Narcissus number.

printf ("%d is not narcissus number \ n", num);

}

}

2. Write a function that specifies the sum of all integers between a number and a number

Such as: 3 to 8, calculate the 3+4+5+6+7+8 =?

void Getn2msum (int n,int m) {

int sum = 0;

If (n < M) {//n smaller than M case

For (int i=n; i<=m; I++) {

Sum + = i;

}

}else{//m is smaller than n

For (int i=m; i<=n; I++) {

Sum + = i;

}

}

printf ("%d to%d and%d\n", n,m,sum);

}

3, Use the function to determine whether a year is a leap years

void Isrunyear (int Year) {

If (year% 400 ==0 | | (year%4==0 && Year%100!=0)) {

printf ("%d years is a leap year \ n";

}else{

printf ("%d is common year \ n", year);

}

}

int main (int argc, const char * Argv[]) {

Call syntax: function name (argument list);

Isflower (200);

Getn2msum (100,1);//10+11+12....+20

Isrunyear (1900);

Return 0;

}

The formal and practical parameters of C language

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.