int a=50;
int b=4;
int *pa=&a;
int *pb=&b;
int total=*pa+*pb;
Serial.println(total);
===========================
一維.陣列指標
Serial.begin(9600);
int a[3]={12,15,18};;
int* pa=a; //陣列本身是指標
Serial.println(*(pa+0));
Serial.println(*(pa+1));
Serial.println(*(pa+2));
========================
二維陣列指標
Serial.begin(9600);
int a[2][3]={{12,15,18},{45,65,98}};
int (*pa)[3]=a;
Serial.println(*(*(pa+0)+0));
Serial.println(*(*(pa+0)+1));
Serial.println(*(*(pa+0)+2));
Serial.println(*(*(pa+1)+0));
Serial.println(*(*(pa+1)+1));
Serial.println(*(*(pa+1)+2));
==================================
字元
Serial.begin(9600);
char k='a';
char* pk;
pk=&k;
Serial.println(*pk);
==============================
字串
Serial.begin(9600);
char *k="hello";
Serial.println(k);
}
===============================
字串陣列
Serial.begin(9600);
char *str[]={"hello","bill","mary"};
for(int i=0;i<3;i++)
{
Serial.println(str[i]);
}
=================
雙層指標
Serial.begin(9600);
int t=50;
int *pt=&t;
int **ph=&pt;
Serial.println(**ph);
========================
函數指標
void hello(); //先宣告
void (*f)()=hello;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
(*f)();
}
void loop() {
// put your main code here, to run repeatedly:
}
void hello()
{
Serial.println("Hello!");
}
沒有留言:
張貼留言