1.1 Êý×éµÄÀàÐÍ·ÖÎö
´ÓÁ½¸ö½Ç¶È£º
1£©µØÖ·½Ç¶È£¬Ö¸Õë----->Êý¾ÝÀàÐÍ *, Êý¾ÝÀàÐÍ Ö¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍ
2£©±äÁ¿½Ç¶È£¬±äÁ¿Ãû ±äÁ¿µÄÀàÐÍ
1.1.1 ÆÕͨ±äÁ¿
int a = 10;
a------->±äÁ¿Ãû ±äÁ¿µÄÀàÐÍΪ int
&a----->Ö¸Õë³£Á¿£¬ Ö¸ÕëµÄÀàÐÍΪ£º int * £¬ Ö¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍΪintÀàÐÍ
1.1.2 һάÊý×é
Êý×éÃû£º±íʾÊý×éÊ×ÔªËصĵØÖ·
Êý×éÃû£º±íʾÊý×éµÄÒ»Õû¸öµÄ¿Õ¼ä
char b[4];
1£©´Ó±äÁ¿µÄ½Ç¶È¿´£º
b----->±äÁ¿Ãû ±äÁ¿µÄÀàÐÍΪ char [4] ----->Êý×éÀàÐÍ£¬ aÊÇÊý×éÀàÐ͵ıäÁ¿
&b----->Ö¸Õë³£Á¿ Ö¸ÕëµÄÀàÐÍΪ char (*)[4], Ö¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍΪ char [4]ÀàÐÍ
&b+1 £ºÆ«ÒÆ char [4] ¸ö×Ö½Ú
2£©bÊÇÊý×éÊ×ÔªËصĵØÖ·
b ---->Ö¸Õë³£Á¿£¬Ö¸ÕëµÄÀàÐÍΪ£ºchar * , Ö¸ÕëÖ¸ÏòµÄ¶ÔÏóÀàÐÍΪ char ÀàÐÍ
b+1 £ºÆ«ÒÆ1¸ö×Ö½Ú
#include <stdio.h>
int main() { char a[4] = {1,2,3,4};
//a £º ±íʾÊý×éÊ×ÔªËصĵØÖ·,Ö¸Õ룬ָÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍchar // a,Ö¸Õ룬ָÕëµÄÀàÐÍΪ char *
//a : ±íʾÊý×éµÄÕû¸ö¿Õ¼ä£¬a ±äÁ¿£¬±äÁ¿µÄÀàÐÍΪchar [4] //&a : Ö¸Õ룬ָÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍ char [4] //&a,Ö¸Õ룬ָÕëµÄÀàÐÍ char (*)[4] printf("%#p\n",&a); //&a : Ö¸ÏòµÄ¶ÔÏóµÄÀàÐÍΪ char [4] //*(&a) : a ,Ö¸ÏòµÄ¶ÔÏóµÄÀàÐÍΪ char //&a ------------>*(&a) //Ö¸ÕëÖ¸ÏòµÄ¶ÔÏóÀàÐÍ£ºchar[4] ------->char //Ö¸ÕëµÄÀàÐÍ£ºchar(*)[4] ----->char *----->char printf("%d\n",**(&a));
printf("%#p\n",a);
printf("%#p\n",&a+1); printf("%#p\n",a+1); } |
1.1.3 typedefÀàÐÍÖض¨Òå¹Ø¼ü×Ö
typedef £º¸øÒÑÓеÄÊý¾ÝÀàÐÍÈ¡Ò»¸öеÄÀàÐÍÃû
¸ñʽ£ºtypedef ÔÀ´µÄÀàÐÍ ÐµÄÀàÐÍÃû
ÐÂÀàÐÍÃû·ûºÏ±êʶ·ûµÄÃüÃû¹æÔò
//È¥µôеÄÀàÐÍÃû£¬Ê£ÏµľÍÊÇÔÀ´µÄÀàÐÍ
typedef int(*PN)(int ,int);
1.1.4 ¶þάÊý×é
char a[3][4] = {11,12,13,14,
15,16,17,18,
19,10,11,12
};
a ÓÅÏÈ ¸ú[3]£¬---->a[3]----->Êý×é
a[3]Êý×éÔªËصÄÀàÐÍΪ ----->char [4]----->Êý×éÀàÐÍ
a[3]Êý×éÓÐ3¸öÔªËØ£¬Ã¿¸öÔªËصÄÀàÐÍΪ char [4],ÔªËØΪÊý×éÀàÐÍ£¬
char a1[4];
char a2[4];
char a3[4];
---------------------------------------
typedef char NM[4];
NM [3]; //Êý×é
//Êý×éÔªËصÄÀàÐÍΪ NMÀàÐÍ
//NMÀàÐÍΪ char [4]ÀàÐÍ
typedef char NM[4];
int main() {
NM a[3] = {11,12,13,14, 15,16,17,18, 19,10,11,12 }; int i,j;
//a[3] for(i = 0; i < 3; i++) { for(j = 0; j < 4; j++) { printf("%d ",a[i][j]); } printf("\n"); } } |
#include <stdio.h>
int main() {
char a[3][4] = {11,12,13,14, 15,16,17,18, 19,10,11,12 }; int i,j;
//a £º ±íʾÊý×éµÄÊ×ÐеØÖ·--->a == &a[0] //*a == a[0] //*(a+i) == a[i] ±íʾÊý×éiÐÐÊ×ÁÐÔªËصĵØÖ·
//a + i £º±íʾÊý×éiÐеÄÊ×µØÖ·£¬---->a + i == &a[i] //a[0] : Êý×é0ÐÐÊ×ÁÐÔªËصĵØÖ·-->a[0] == &a[0][0] //a[i] : ±íʾÊý×éiÐÐÊ×ÁÐÔªËصĵØÖ·--->a[i] == &a[i][0] //a[i]+j £º±íʾÊý×éiÐÐjÁÐÔªËصĵØÖ·-->a[i]+j == &a[i][j] //*(a+i)+j == a[i]+j
printf("a: %#p\n",a); //Ö¸ÏòµÄ¶ÔÏóµÄÀàÐÍ char [4] printf("a+1: %#p\n",a+1); //Ö¸ÏòµÄ¶ÔÏóµÄÀàÐÍ char [4] printf("a[0]: %#p\n",a[0]); //Ö¸ÕëµÄ¶ÔÏóµÄÀàÐÍ char printf("a[0]+1: %#p\n",a[0]+1);
printf("&a[1] %#p\n",&a[1]); printf("*a[1] %d\n",*a[1]); printf("**(a+1): %d\n",**(a+1));
printf("*(*(a+1)+1): %d\n",*(*(a+1)+1)); printf("*(a[1]+1): %d\n",*(*(a+1)+1));
printf("----------------------------------\n"); for(i = 0; i < 3; i++) { for(j = 0; j < 4; j++) { //printf("%d ",a[i][j]); //printf("%d ",*(a[i]+j)); printf("%d ",*(*(a+i)+j)); } printf("\n"); } } |