.這是 pointer。

用 C tutor 跑的 pointer。
| 1 | #include <stdio.h> |
| 2 | int main() { |
| 3 | int a=100; |
| 4 | int b=100; |
| 5 | int *p; |
| 6 | |
| 7 | p=&a; |
| 8 | printf ("%d \n",*p); |
| 9 | |
| 10 | p=&b; |
| 11 | printf ("%d \n",*p); |
| 12 | return 0; |
| 13 | } |

讓箭頭飛一會。
PImage img1,img2,img3;
PImage img;
float x=100,y=100,vx=0;
void setup()
{
size (1000,1000);
img1=loadImage("img1.png");
img2=loadImage("img2.png");
img3=loadImage("img3.png");
img=img3;
}
void draw()
{
background (255);
image (img,x,y);
x+=vx;
}
void keyPressed()
{
if (keyCode==LEFT)
{
img=img2;vx=-1;
}
else if (keyCode==RIGHT)
{
img=img1;vx=+1;
}
}
void keyReleased()
{
img=img3; vx=0;
}

| 1 | #include <stdio.h> |
| 2 | char s1[30]="hello world I love you"; |
| 3 | char s2[30]="I am a book and he is not"; |
| 4 | int main() { |
| 5 | char *p; |
| 6 | char a[10]; |
| 7 | p=s1; |
| 8 | printf ("%s \n",*p); |
| 9 | p=s2; |
| 10 | printf ("%s \n",*p); |
| 11 | } |
沒有留言:
張貼留言