c Definition and assignment of one-, two- and three-dimensional arrays

1. When defining an array, you must specify the size of the array, that is, how much storage space is used to store the array.

2. The array must be defined in the standard format of the array: array name + subscript.

3. Only strings can be defined using pointers

4. All numbers and structs in c can be understood as char arrays

For example, int is a 4-byte char array


#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>  //v4l2 头文件
#include <string.h>
#include <sys/mman.h>
#include <linux/fb.h>

int main(void){
	
//	char *q={1,2,3};      这种用指针定义数组是错误的,指针只能定义字符串数组
	char *q="1234";       //只有字符串可以用指针定义
	
     
	 char i1[10];
	 i1[2]=1;
	 *(i1+3)=8;     //1+3 列
	
 // 	printf("%d\n", i1[3]);
	
	char i2[5][3]={};

	
	i2[0][0]=1;
	i2[1][1]=2;
	
	*((*i2)+2)=3;             //表示1排2+1列
	*(*(i2+4)+1)=4;           //表示1+4排1+1列
	
	
	for(int a=0;a<5;a++){
		for(int b=0;b<3;b++){
	//		printf("%d ",i2[a][b]);
		}
	//	printf("\n");
	}
	
	
	char i3[2][5][3]={};       //可以把i3 理解为[2]的指针
	
	i3[0][1][2]=1;             
	
	*(*(*(i3+1)+2)+2)=9;       //指针赋值: i3+1 指的是[2],中间的*+2=[5],外围的*+2=[3]
	
	char o[3]={1,2,3};
	memcpy(&(i3[1][3][0]),o,3);  //数组赋值
	
	
	for(int a=0;a<2;a++){
		for(int b=0;b<5;b++){
			for(int c=0;c<3;c++){
			 printf("%d ",i3[a][b][c]);
			}
			printf("\n");
		}
		printf("\n");
	}
	

   
	
	return 0;
}

Guess you like

Origin blog.csdn.net/m0_59802969/article/details/134913917