C sets the parameters for the function, and how to define the function with two parameters

Updated on technology 2024-02-13
4 answers
  1. Anonymous users2024-02-06

    define the function void f(int q, int w, int e=0);

    e=0 is the default argument, when the function is called f(1,2), then e=0

    The latter is that it cannot be written like this void f( int q, in w=0, int e);

  2. Anonymous users2024-02-05

    For example, a function declares void f(type p1, type p2, type p3, type p4).

    If you want to use the default parameter, you can declare it as void f(type p1, type p2, type p3, type p4=default).

    or void f(type p1, type p2, type p3=default, type p4=default).

    and void f(type p1, type p2=default, type p3=default, type p4=default).

    and void f(type p1=default, type p2=default, type p3=default, type p4=default).

    However, it cannot be declared void f(type p1, type p2, type p3=default, type p4).

    Here's why: the default parameter can be omitted, so if you pass in three parameters, the compiler doesn't know if it's an omission or some kind of error, so all default parameters must be on the right, and if there are any parameters after the first default, they must be default parameters.

    Once a default parameter is omitted during the call, all subsequent arguments must be omitted, otherwise it will cause confusion in the compilation system and cause incorrect calls.

  3. Anonymous users2024-02-04

    For example, let's take the following function.

    int fun(int a,int b,int c=3)c is the default argument specified, usually specified in the function prototype. 3 is given here as the default parameter. Call this function fun(4,5,6) as usual; Then it's a=4, b=4, c=6.

    If fun(1,2) is called in this way, then it is a=1, b=2, c=3, where c is not specified, because c is the default argument, there is already a default value, here c is to use the default value of 3.

    Why the default argument must be the rightmost parameter in the function parameter table? Change the above function to int fun(int a=3,int b,int c){} so that fun(1,2) is called, so that a=1, b=2, and c does not have a value assigned at all, so it is wrong. These parameters are all one-to-one.

  4. Anonymous users2024-02-03

    1. The function definition form of C++:

    Return value type Function name ( Parameter 1, Parameter 2, Parameter 3,......2. Example:

    int addit(int a,int b) } is the end of the function marker.

    3. P.S. Learning programming requires a certain amount of understanding, a bit of an algebraic mindset in middle school.

Related questions
6 answers2024-02-13

I majored in computer science, and I was embarrassed when I first learned C language, but I also had some experience. >>>More

18 answers2024-02-13

Is your "2012-07-23" a field? If you can directly use the substitution function to replace the year, month and day with "-", it will save trouble.

6 answers2024-02-13

The steps to set it up are as follows:

1.Data connection settings Go to Settings Data Connection menu Connection, and delete everything in the dial-up connection, VPN connection, server connection, GPRS connection! >>>More

13 answers2024-02-13

When you install the program, it will prompt you which disk to install it on? Usually C: Programs ... >>>More

5 answers2024-02-13

#include

#define m 5 >>>More