一.指针
1.
# include < stdio .h >main ( ){ int x[ ] = {10, 20, 30, 40, 50 };int *p ;p=x;printf ( “%d”, *(p+2 ) );}
运行结果为:30
2.
#include <stdio.h>main( ){char s[]=”abcdefg”;char *p;p=s;printf(“ch=%c\n”,*(p+5));}
运行结果为:ch=f
3.
#include<stdio.h>main ( ){int a[]={1, 2, 3, 4, 5} ;int x, y, *p;p=a;x=*(p+2);printf("%d:%d \n", *p, x);}
运行结果为:1:3
4.
#include<stdio.h>main(){ int arr[ ]={30,25,20,15,10,5}, *p=arr;p++;printf(“%d\n”,*(p+3));}
运行结果为: 10
5.
#include <stdio.h>main( ){int a[ ]={1, 2, 3, 4, 5, 6};int x, y, *p;p = &a[0];x = *(p+2);y = *(p+4);printf(“*p=%d, x=%d, y=%d\n”, *p, x, y);}
运行结果为:*p=1, x=3, y=5
6.
#include<stdio.h>main( ){static char a[ ]=”Program”, *ptr;for(ptr=a, ptr<a+7; ptr+=2)putchar(*ptr);}
运行结果为:Porm
7.
#include <stdio.h>char s[]=”ABCD”;main(){char *p;for(p=s;p<s+4;p++)printf(“%c %s\n”,*p,p);}
运行结果为:A ABCDB BCDC CDD D
二. 结构体
1.
#include<stdio.h>struct st{ int x;int y;} a[2]={5, 7, 2, 9} ;main(){printf("%d\n",a[0].y*a [1].x);}
运行结果是:14
2.
#include<stdio.h>main( ){struct stu{int num;char a[5];float score; } m={1234,”wang”,89.5};printf(“%d,%s,%f”,m.num,m.a,m.score);}
运行结果是:1234,wang,89.5
3.
#include<stdio.h>struct cmplx{ int x;int y;} cnum[2]={1, 3, 2, 7};main( ){printf(“%d\n”, cnum[0].y * cnum[1].x );}
运行结果是:
6
4.
#include <stdio.h>struct abc{ int a, b, c; };main(){struct abc s[2]={{1,2,3},{4,5,6}};int t;t=s[0].a+s[1].b;printf("%d \n",t);}
运行结果是: 6