当前位置:网站首页>c语言指针练习题
c语言指针练习题
2022-08-09 23:42:00 【BSP初级小学僧】
1、使用指针方法,计算两个数组中各元素对应位置的和,和的结果存入第三个数组中,然后输出。
#include <stdio.h>
void count(int *p1,int *p2,int *p3,int x);
int main()
{
int arr01[4]={2,4,5,8};
int arr02[4]={1,0,4,6};
int arr03[4];
count(arr01,arr02,arr03,4);
}
void count(int *p1,int *p2,int *p3,int x)
{
int i;
for(i=0;i<x;i++)
{
*(p3+i) = (*(p1+i))+ (*(p2+i));
}
printf("两个数组对应各元素和分别为:\n");
for(i=0;i<x;i++)
{
printf("%d ",p3[i]);
}
}
运行结果:
2、利用指针,顺序输出字母表,然后反序输出。
#include <stdio.h>
#include <malloc.h>
int main()
{
char *p01=(char *) malloc(sizeof(char)*26);
char *p02=(char *) malloc(sizeof(char)*26);
int i;
printf("大写字母顺序输出:\n");
for(i=0;i<26;i++)
{
*(p01+i)=('A'+i);
printf("%c ",*(p01+i));
}
printf("\n\n");
printf("小写字母顺序输出:\n");
for(i=0;i<26;i++)
{
*(p02+i)=('a'+i);
printf("%c ",*(p02+i));
}
printf("\n\n");
printf("大写字母反序输出:\n");
for(i=25;i>=0;i--)
{
printf("%c ",*(p01+i));
}
printf("\n\n");
printf("小写字母反序输出:\n");
for(i=25;i>=0;i--)
{
printf("%c ",*(p02+i));
}
return 0;
}
运行结果:
边栏推荐
- abicc 知:API compatibility report 介绍
- 数字孪生智慧制造生产线项目实施方案,平台认知与概念
- 关于HBuilder X鼠标变为_ 替换字符的问题
- 阿里云短信服务开通
- Golden Warehouse Database KingbaseGIS User Manual (6.4. Geometry Object Access Function)
- 3.11-程序基本的控制语句 3.12-表达式 3.13-数据类型 3.14-常量/变量 3.15-标识符
- 拼多多店铺运营不得不知的留个运营小知识
- [C language] Address book "Static Memory Version"
- Distributed database problem (3): data consistency
- 【剑指offer】第一题 第二题
猜你喜欢
Wireshark classic practice and interview 13-point summary
ES6 Beginner to Mastery #15: Generator Usage
【剑指offer】第一题 第二题
3.11-程序基本的控制语句 3.12-表达式 3.13-数据类型 3.14-常量/变量 3.15-标识符
服务发现@EnableDiscoveryClient
算法---整数替换(Kotlin)
分布式数据库难题(三):数据一致性
Distributed database problem (3): data consistency
博弈小游戏
数字孪生电力系统,可视化应用实现科学调度的电子设备
随机推荐
Leetcode80. 删除有序数组中的重复项 II
NTU General Database-Gbase-8a-Learning-04-Deploying Distributed Clusters
Leecode-205. 同构字符串
【剑指offer】第一题 第二题
abicc 知:API compatibility report 介绍
Pinduoduo store operation must know to leave a little knowledge of operation
Golden Warehouse Database KingbaseGIS User Manual (6.6. Geometric Object Verification Function, 6.7. Spatial Reference System Function)
Golden Warehouse Database KingbaseGIS User Manual (6.4. Geometry Object Access Function)
New window Display Agreement
ES6 Beginner to Mastery #15: Generator Usage
Web性能测试模型小结
Redis 大 key 要如何处理?
【C语言】指针和数组的深入理解(第四期)
源码编译安装LAMP和LNMP
无源晶振负载电容值CL匹配方法及说明
deepstream学习笔记(三):deepstream-imagedata-multistream解析与接入适配yolov5模型测试
nfs配置
《痞子衡嵌入式半月刊》 第 60 期
3.1 - 程序设计语言 3.2 - 高级语言的特点及引用 3.3 - 静态/动态类型语言
Service Discovery @EnableDiscoveryClient