当前位置:网站首页>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;
} 运行结果:

边栏推荐
- 线程的同步与互斥
- 上交所实时行情文件汇总
- The technical aspects of the byte have been passed, and the salary has been negotiated for 20K*13, but the result is still being brushed. I asked the HR why...
- 考柏的感慨
- router路由
- NTU General Database-Gbase-8a-Learning-04-Deploying Distributed Clusters
- Project (7) - PolarSeg point cloud semantic segmentation
- mysql无法远程连接 Can‘t connect to MySQL server on ‘xxx.xxx.xxx.xxx‘ (10060 “Unknown error“)
- Creo5.0入门教程赠素材
- 蔚来杯2022牛客暑期多校训练营7 CFGJ
猜你喜欢

Wireshark classic practice and interview 13-point summary

dlopen failed: library "libtaml.so" not found

基于 LSTM 的分布式能源发电预测(Matlab代码实现)

数字孪生电力系统,可视化应用实现科学调度的电子设备

RebatMq消息中间件(一) 各个中间件介绍

2022金九银十工作潮,怎么样才能成功跳槽面试拿到高薪呢?

CST Studio Suite 2021 software installation package and installation tutorial
![[C language] Address book](/img/56/a72900c22b965947ee88256d8f6c21.jpg)
[C language] Address book "Static Memory Version"

线程的同步与互斥
![[C language] In-depth understanding of pointers and arrays (issue 4)](/img/22/ad31b47bb8cc1722121959efddefd5.png)
[C language] In-depth understanding of pointers and arrays (issue 4)
随机推荐
selenium和驱动安装
从TRPO到PPO(理论分析与数学证明)
阿雷的血压有些低
大龄测试员刚迈过了 35 岁这个“坎儿”,和大家说点儿心里话
考柏的感慨
dlopen failed: library "libtaml.so" not found
RebatMq消息中间件(一) 各个中间件介绍
Copper's emotion
Why don't suggest you run in Docker Mysql?
ECCV 2022 | Microsoft Open Source TinyViT: Pre-training Capabilities for Small Models
When knowledge and action are one
数据库的备份与恢复「建议收藏」
Leetcode82. 删除排序链表中的重复元素 II
CST Studio Suite 2021 software installation package and installation tutorial
JSP简介
WPF DataGrid using data templates
新开窗口 展示协议
Digital wallets, red sea ecological rapid introduction of small programs can help capture device entry wisdom
构建平衡二叉树「建议收藏」
共创 Ray 中文社区,Ray Forward Meetup 2022 直播邀你参加!