An array of function parameter transfer in C language (RPM)

Source: Internet
Author: User

In the VC write programs are accustomed to, general array as function arguments, the most commonly used method is the method of reference and pointers, but to C language there is no reference, there is a more common method:

#include <stdio.h>


void sort (int array[],int n)
{
int i,j,k,t;
for (i=0;i<n-1;i++)
{
K=i;
for (j=i+1;j<n;j++)
if (array[j]<array[k]) k=j;
t=array[k];array[k]=array[i];array[i]=t;

}

}

int main (void)
{
int a[10],i;
printf ("Enter the array");
for (i=0;i<10;i++)
scanf ("%d", &a[i]);
Sort (a,10);
printf ("The sorted array:");
for (i=0;i<10;i++)
printf ("%d", a[i]);
}




}

This is an example of the rectification book, the selection method to sort the array, it is said that the algorithm is faster than bubbling method, there is a chance to use vtune measurement, here is the key is the formal parameter notation int array[], in fact, the equivalent of a pointer or reference.

Here are the things about local variables and global variables

Sometimes in programming, you want some external variables to be referenced only by this file, not by other files. You can then add a static declaration when defining an external variable.

(static) intrinsic function

If a function defined in a source file can only be called by a function in this file and cannot be called by a function in another file of the same source program, this function is called an internal letter
Number. The general form of defining intrinsic functions is the static type descriptor function name (formal parameter list) such as:
The static int f (int a,int b) Intrinsic function is also known as a statics function. But the meaning of static statics here is not a means of storage, but refers to the function of the scope of the call is confined to this file. Therefore, it is not confusing to define static functions with the same name in different source files.

External functions
External functions are valid throughout the source program and are defined in the general form: extern type specifier function name (formal parameter list) for example:
extern int f (int a,int B) is implied as extern or static if it is not stated in the function definition. When calling external functions defined in other source files in a function of a source file, the extern description is applied as an external function. For example:
F1. C (source file i)
Main ()
{
extern int F1 (int i); /* External function description, indicating F1 letter
Number in other source files */
......
}
F2. C (source file II)
extern int F1 (int i); /* External function definition */
{
......
}

An array of function parameter transfer in C language (RPM)

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.