The problem of using functions as formal arguments to functions in the C language

Updated on technology 2024-03-10
8 answers
  1. Anonymous users2024-02-06

    You can use function pointers, such as:

    voidfunction(int

    x,void

    visit) () *no return value, no arguments **other***

    visit();

    voidfunction(int

    x,void

    visit)(int)) *no return value, there is a shaping parameter *intyx*x; *Other***

    visit(y);

  2. Anonymous users2024-02-05

    This problem shows that you are still not proficient in the use of pointers, since it is an array, and the first address of the array is passed as a function parameter.

    #include

    #include

    voidfunc1(int

    array,intsize)

    Array B gets the element value based on the number of elements of array a multiplied by the number of terms.

    voidfunc2(int

    array_a,int

    array_b,intsize)

    Output array elements.

    voidprint(int

    array,intsize)

    intmain(void)

  3. Anonymous users2024-02-04

    The call of the function in the array is called by the array name as a real argument, because the name of the array is the first address of the array, so the call to the array does not need to return the value, and the array value in the main tone function will change with the change of the shape parameter group of the modulated function, of course, these are all under the premise that you use the array name as the argument.

  4. Anonymous users2024-02-03

    If the passing value is a pointer (address), that is, the name of the array, although it is in the subfunction, it is the address that is copied in the past, so you can operate on the content pointed in the address, that is, you can operate on multiple values in a subfunction, if you pass the content, at most a return value operation is carried out by return, in short, it depends on what you pass.

  5. Anonymous users2024-02-02

    nt *&pvec is a reference to the int type pointer in C++, that is, the PVEC itself is a reference to the argument when the function is called, and the type of the argument is a pointer type to the integer type, and the reference is used because the content of the pointer needs to be modified in the function. (If you only need to modify the contents of the memory unit that the pointer points to, you only need to use the pointer type as the parameter).

    The size in int &size is also a reference, which is a reference to the int type, and the purpose is to modify the value of the reference argument.

    fstream is a file stream type in C++, which can be read or written, and fstream& can pass in an object of type fstream, and the purpose of the function is also to modify the content of the original arguments, and the reference will not copy the arguments.

  6. Anonymous users2024-02-01

    When declaring a function, you only need to write out the parameter type.

    When defining a function, you must write out the parameter type and variable name.

    The standard function printf in C uses this mechanism. When declaring a function that is uncertain about the parameters, the parameters part can be marked with the ellipsis "...."Instead. “…Tell the compiler not to check whether the parameter type is the same as the argument type when the function is called, nor to check the number of parameters.

  7. Anonymous users2024-01-31

    It depends on whether you need parameters for the function of the function.

    For example, this does not need parameters:

    void print()

    main()

    Result: test

  8. Anonymous users2024-01-30

    Foreword:

    Sometimes we need a function interface that can support variable parameters to improve their generalization ability, such as defining a summation function that sums all the incoming parameters and returns them, and C provides a way to help us achieve this.

    Principle:

    If we can know the address and type of the previous parameter of the variable parameter list, we can know the first address of the variable parameter list, and then extract the corresponding data according to the type of each parameter. To put it simply, the data in the stack is taken out in turn according to the size of the specified type.

    Concrete implementation:Step Analysis:

Related questions
6 answers2024-03-10

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

12 answers2024-03-10

In C, the types of functions can be divided into the following types: >>>More

11 answers2024-03-10

Valid variable names for the C language:

First, it can only contain numbers, letters, and underscores. >>>More

8 answers2024-03-10

The semicolon is the sign of the end of the statement, but the semicolon is not used after the loop, if, and subfunctions such as long long a (int b), and everything else is used, but two semicolons cannot be added, although it will not cause an error, but it may affect the result.

11 answers2024-03-10

using systme;

using ; >>>More