LMS知識社群歷程檔案Login
Position: 吳驊軒 > GBook > 指標
/*float pi = 3.14159;
  float* ptr=NULL;
  ptr=π
  printf("%.5f (%p)\n",pi,&pi);
  printf("%.5f (%p)",*ptr,ptr);
char name[] = "CSIE";
char* ptr = name;
int a;
for(a=1;a<=4;a++){
printf("%p %c %c\n", ptr,*ptr,*ptr+a);
ptr=name+a;
}
printf("%p %c\n",ptr,*ptr);
int score[] = {10, 20, 30, 40};
int* ptr = score;
printf("%p %d\n", ptr,*ptr); //印出?
ptr = score + 1;
printf("%p %d\n", ptr,*ptr); //印出?
ptr = score + 3;
printf("%p %d\n", ptr,*ptr);
float arr[] = {0.2,0.5,0.8};
int a;
  float *ptr=NULL;
  ptr=&arr;
  for(a=1;a<=3;a++){
  printf("%p %.2f\n",ptr,*(float*)(ptr+a-1));
}
int arr[50];
int a,b;
  int* ptr=&arr;
  memset(arr,0,sizeof(arr));
  scanf("%d",&b);
  for(a=0;a<b;a++){
  scanf("%d",&arr[a]);
  }
  for(a=0;a<b;a++){
  if(arr[a]%2==0){
  printf("%p %d\n",ptr,*(ptr+a));
}
int arr[50];
int n = 0;
int* ptr = arr;
while(scanf("%d", (ptr+n))) {
n++;
if(getchar() == '\n') {
break;
}
}
int i;
for(i=0;i<n;i++) {
int n = *(ptr+i);
if(n % 2 == 0) {
printf("%d ", n);
}
}
printf("\n");
int m[2][3] = {{10, 20, 30},{40, 50, 60}};
int *ptr = m;
printf("%p %d\n",ptr,*(ptr+2));//印出?
// 如何用指標存取m[i][j]?
// *(ptr + i * row + j)
// 例如,m[1][2]即為*(ptr+1*3+2)
printf("%d\n", *(ptr+1*3+2)); // 60*/
Reply