C language expert, about function definitions

Updated on technology 2024-05-11
6 answers
  1. Anonymous users2024-02-10

    #include

    void sort(int arr,int n);

    void main ()

    int a[10];

    sort(a,10);

    void sort(int arr,int n)int i,j,k;

    Compare * for(i=0; iarr[j+1])

    output * for(i=0; i<10;i++)

    printf("%6d",arr[i]);

    Function declarations and definitions have also been modified, and the parameters are preceded by a type description.

  2. Anonymous users2024-02-09

    You should read some books.

    Custom function definitions:

    Definition of the function.

    A function consists of two parts: a function header and a statement body.

    The function header consists of the following three parts:

    The type of value returned by the function.

    The name of the function. Parameter table.

    A complete function should look like this:

    Function Return Value Type Function name (parameter table).

    sentence body; Addendum: You add a {} after (); See if you can get by.

  3. Anonymous users2024-02-08

    You didn't declare a function type (warning), and the parameter type is also an error.

    void sort(int arr,int arr_n);

    void main ()

    int a[10];

    scanf("%d%d%d%d%d%d%d%d%d%d",a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9]);

    sort(a,10);

    system("pause");

    void sort(int arr,int arr_n)int i,j,k;

    Compare * for(i=0; iarr[j+1])

    output * for(i=0; i<10;i++)

    printf("%6d",arr[i]);

  4. Anonymous users2024-02-07

    The process of encapsulating a segment into a function is called a function definition.

    Functions can be reused to perform a function independently, with or without receiving data passed by the user. Functions that receive user data need to be defined with parameters, and functions that do not receive user data do not need to be specified.

    Functions can't be nested definitions, and main is also a function definition, so put sum outside of main. Functions must be defined before they are used, so sum should be placed before main.

    The parameters given when the function is defined are called formal parameters, referred to as formal parameters; The arguments (that is, the data passed) given when the function is called are called the actual parameters, referred to as the actual parameters. When a function is called, the value of the argument is passed to the parameter, which is equivalent to an assignment operation.

    In principle, the type and number of parameters should be consistent with those of the form parameters. If automatic type conversion is possible, or if a forced type conversion is performed, then the parameter type can also be different from the parameter type, for example, if an int argument is passed to a float argument, an automatic type conversion will occur.

  5. Anonymous users2024-02-06

    void main() does not return a value.

    int main() has an int return value.

  6. Anonymous users2024-02-05

    Classification from the perspective of parameters:1There are argumentative functions:

    Functions have tangible parameters, which can be one, or several, and the type of arguments is arbitrary, depending entirely on the function of the function. 2.Parameterless functions:

    The function has no arguments, writes a viod or nothing at the place of the list of parameters.

    Every C program has at least one function, that is, the main function main(), if the task of the program is relatively simple, all ** are written in the main() function, however, in actual development, the task of the program is often more complex, if all ** are written in the main() function, the main() function will be very large and bloated, the structure is complex, and ** repeated.

    Details: We can divide ** into different custom functions according to the logic of the program and the division of tasks, main() is more concerned about the business logic and processing process, and when you need to perform specific tasks, you can call these custom functions.

    For the sake of understanding, we divide functions into two types: library functions and custom functions. Library functions are provided by the C language or the system, and implement some basic functions, such as scanf and printf, which can be used directly in the program.

    A custom function is a function that a programmer writes to accomplish a task, in order to implement a certain function or to make the main program more concise. Before a programmer can use a custom function, it must be declared and defined.

Related questions
4 answers2024-05-11

I've seen questions like this, and I don't understand what you mean, but I think it's like this, structab; I hit ... where you can add definitions of all data forms, e.g., int >>>More

8 answers2024-05-11

Isn't it over if you do a division of seconds?

5 answers2024-05-11

These are not macro definitions, these are file containments. >>>More

6 answers2024-05-11

c, the assignment operation requires that the lvalue is of the same type as the rvalue. >>>More