"C Language" and "algorithm" are used to access arrays in multiple ways. The C language array Sorting Algorithm

Source: Internet
Author: User

"C Language" and "algorithm" are used to access arrays in multiple ways. The C language array Sorting Algorithm

1 #include <stdio.h>
 2 
 3 // Use array names and pointer variables, respectively, to input and output all elements of the array using the following notation and pointer
 4
 5 int main () {
 6 int i = 0;
 7 int array [6];
 8 int * p = array;
 9 printf ("\ n Please input array [6]: \ n");
10 while (p <(array + 6))
11 scanf ("% d", p ++);
12 printf ("\ n Output array [i]: \ n");
13 for (i = 0; i <6; i ++) / * (1) array name, subscript method * /
14 printf ("% d,", array [i]);
15 printf ("\ n Output * (array + i): \ n");
16 for (i = 0; i <6; i ++) / * (2) array name, pointer method * /
17 printf ("% d,", * (array + i));
18 printf ("\ n Output p [i]: \ n");
19 p = array;
20 for (i = 0; i <6; i ++) / * (3) Pointer variable, subscript method * /
21 printf ("% d,", p [i]);
22 printf ("\ n Output * (p + i): \ n");
23 for (i = 0; i <6; i ++) / * (4) pointer variable, pointer method * /
24 printf ("% d,", * (p + i));
25 printf ("\ n Output * p ++: \ n");
26 while (p <(array + 6)) / * (5) pointer variable, pointer method, the most efficient * /
27 printf ("% d,", * p ++);
28 printf ("\ n");
29 return 0;
30}

 

1 #include <stdio.h>
  2 
  3 // Output the address of the subarray and elements of the two-dimensional array
  4
  5 int main () {
  6 int i = 100, j = 200, k = 300;
  7 int b [3] [5] = {{31,32,33,24,25}, {16,17,8,9,10}, {19,11,51,14,15}};
  8 printf ("& i =% X & j =% X & k =% X \ n", & i, & j, & k);
  9 printf ("b =% X b + 1 =% X b + 2 =% X \ n", b, b + 1, b + 2);
10 printf ("b [0] =% X b [0] + 1 =% X b [0] + 2 =% X \ n", b [0], b [0] + 1, b [0] + 2);
11 printf ("b [1] =% X * (b + 1) =% X & b [1] [0] =% X \ n", b [1], * (b + 1), & b [1] [0]);
12 printf ("b [2] [4] =% d * (* (b + 2) +4) =% d \ n", b [2] [4], * (* (b + 2) +4 ));
13 return 0;
14} 

 


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.