Operate two-dimensional array C language with pointers

Source: Internet
Author: User


// Use a pointer to operate a two-dimensional array float (* pointer) [4], pointerIs a float * Type Variable, To see clearly! Points to a one-dimensional array with four elements.

Float * search (float (* pointer) [4], int N)

See this writing!

// Note !! * (Pointer + n) and (* pointer + n.
// Pointer Points to a two-dimensional array !! That is, pointer is of the int ** type. * pointer + N is equivalent to adding N to the subscript of one-dimensional array.

Int main(){
Float score[][4] = {{60,70,80,90},{56,89,67,88},{34,78,90,66}};// score +i is the ground i First address
Float * search(float (*pointer)[4], int n); //(*pointer)[4] ? represents an array of ones
Float * p;
Int i,m;
Printf("Enter the number of students:");
Scanf("%d",&m);
p = search(score,m);
For(i=0; i<4; i++)
Printf("%5.2f\t",*(p+i));
Printf("\n");


Float * search(float(* pointer)[4],int n){
Float * pt;
Pt = *(pointer+n);
Return(pt);
}


Return 0;
} 
Related Article

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.