C Language Pointer application

Source: Internet
Author: User

Pointer variables point to array elements:

#import <stdio.h>int Main () {    int a[10]={1,2,3,4,5,6,7,8,9,0};    int *p;    P=a;    for (; p<a+10;)        printf ("%d\n", *p++);}

The array name does the function parameter:

#import <stdio.h>void Main () {    void anv (int *x,int n);    int a[10]={1,2,3,4,5,6,7,8,9},*p;    P=a;    for (; p<a+9; p++)        printf ("%3d", *p);    printf ("\ n");    P=a;    ANV (p,9);    for (; p<a+9; p++)        printf ("%3d", *p);    printf ("\ n");} void Anv (int *x,int n) {    int *a,*i,*j,temp,t;    a=x;    I=a;    j=a+n-1;    t= (n-1)/2;    for (; i<a+t; i++,j--)    {        temp=*i;        *i=*j;        *j=temp;    }    return;}

 

Selection method to 10 integers arranged from large to small

#import "stdio.h" void Main () {    void inv (int *x,int n);    int a[10]={2,4,3,5,1,6,6,4,5,8};    int *p;    p=a;//(P has a definite value)    inv (P, ten);    for (;p <a+10;p++)        printf ("%3d", *p);    printf ("\ n");} void Inv (int *x,int n) {    int *i,*k,*j,t;    i=x;    for (; i<x+n-1; i++)    {        k=i;        for (j=i+1; j<x+n; j + +)        {            if (*j>*k)            {                k=j;            }        }       if (k!=i)        {            t=*i;*i=*k;*k=t;        }    }    return;}

  

string pointers do function arguments

#import "stdio.h" void Main () {    void inv (char *x,char*y);    Char *a= "ASDF";    Char *b= "LKJH";    printf ("%s\n%s\n", A, b);    Inv (A, b);    printf ("%s\n%s\n", A, b);} void Inv (char *x,char *y) {    while ((*x++=*y++)! = ') ');}

  

Returns a pointer to a function, gets a return address value, a pointer to an array of variables to hold a two-dimensional array of a beginning address

#import "stdio.h" void Main () {    float *b (float (* p) [4],int n);    Float a[][4]={1,2,3,4,5,6,7,8,9,1,2,3};    int m,i;    float *c;    printf ("Shuruxuehao:");    scanf ("%d", &m);    printf ("The scores of%d is:\n", m);    C=b (a,m);    for (i=0; i<4; i++)    {        printf ("%5.2f", * (C+i));    }    printf ("\ n");} Float *b (Float (* p) [4],int N) {    float *d;    d=* (p+n);    return D;}

  

 

C Language Pointer application

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.