C语言习题-指针-结构体

一.指针 

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 ABCD
B BCD
C CD
D 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
  • 36
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值