Summary of array knowledge in 19-C language

First, the array 1. array basis

An array is a collection of the same type of data, all of which have the same name. Arrays are widely used in large numbers of processing and string manipulation. Arrays play a very important role in the C language.
Define an array with 10 elements of type int type type name (int[10]) + variable name (arr)

2. Array fully initialized #includeint main(void) { int arr[5] = {1,2,3,4,5,}; printf("arr[2] = %d", arr[2]); } Root@ubuntu:/mnt/hgfs/SHARE/2# ./a.outarr[2] =33. Array traversal

The array subscript is out of bounds, the compiler does not check, improve efficiency

#includeint main (void) { int arr[5]={1,2,3,4,5}; int i =0;for(i; i<5; i++) { printf("arr[%d]= %d", i, arr[i]); } } root@ubuntu:/mnt/hgfs/SHARE/2# ./a.outarr[0]=1arr[1]=2arr[2]=3arr[3] =4arr[4]=54. The array part is initialized intarr[5]; intarr_[5] = {1}; intarr_3[5] = {}; intarr_4[5] = {[2]=100}; Intnum =0; scanf("%d",&num);intarr[num]={};//error: variable-sized object may not be iniTIalized cannot initialize a variable size object. / / Array format is a constant, this is the variable 6. left and right values

The left value represents the memory space, and the right value represents the value (memory space content)
The array name is the right value, the address is printed, the first address of the first element of the number

*i = arr+1 points to the second element of the array
*i = &arr+1 points to the first element after the entire array

7. Pass value call

The function call is just the name of the variable passed into the argument. When the array name is used as a parameter, the size of the array itself is lost, and it degenerates into a pointer. The array name is used as a parameter, and its own size (number) is added.

Second, the application of the array 1. Bubble sort #includeintmain (void) {intarr[10]; inTI =0, j =0, temp =0; printf ("Please enter 10 number:"); for (i; i <10; i++) scanf("%d",arr+i);for(i=0; i<10; i++)printf("%2d",arr[i]);printf("after sorting"); For(i=0; i<9; i++) {for(j=0; j<9-i; j++) {if(arr[j] > arr[j+1]) { temp = arr[j]; Arr[j] = arr[j+1]; arr[j+1] = temp; } } }for(i=0; i<10; i++) {printf("%2d",arr[i]); }printf(""); } root@ubuntu:/mnt/hgfs/SHARE/1# ./a.out Please enter 10 numbers after sorting 01233456782. Select sort #includeintmain(void) {intarr[10];inTI = 0, j =0, temp;printf("Please enter 5 numbers:");for(i=0; i<5; i++) scanf("%d",&arr[i]);for(i=0 ; i<5; i++)printf("%2d",arr[i]);printf("after sorting");for(i=0; i<5; i++) {for(j=i+1; j <5; j++) {if(arr[i] for(i=0; i<5; i++) {printf("%2d",arr[i]); }printf(""); } root@ubuntu: /mnt/hgfs/SHARE/1# ./a.out Please enter 5 numbers after sorting 865423. Binary conversion #includeintfun(void) {chararr[100]={0}, i =0;inta =0, ​​b =0;printf("Please enter a number:");scanf("%d",&a);printf("Please enter the converted hexadecimal number: ");scanf("%d",&b);do{ arr[i] = a % b; a = a / b; i++; }while(a >0);for(i=i-1; i> =0;i--) {if(arr[i] <10) {printf("%d",arr[i]); }else{printf("%c",arr[i]-10+'A '); } } }intmain(void) { fun(); } root@ubuntu:/mnt/hgfs/SHARE/1# ./a.out Please enter a number: 666 Please enter the converted radix: 1629A

Stylus Pen For Microsoft Surface

Product catagories of Stylus Pen For Microsoft Surface, which just can be worked on below Surface model, Please confirm your surface model before buying.

Microsoft Surface 3; Microsoft Surface Pro 3; Microsoft Surface Pro 4; Microsoft Surface Pro 5; Microsoft Surface Pro 6; Microsoft Surface Book; Microsoft Surface Laptop; Microsoft Surface Studio.

Stylus Pen For Microsoft Surface,Tablet Touch Pen,Touch Screen Stylus Pen,Universal Stylus Pen

Shenzhen Ruidian Technology CO., Ltd , https://www.wisonens.com

Posted on