当前位置:网站首页>[C Language Brush Questions] Three Questions for Getting Started with Pointers | String Length, String Copy, Two Number Swap
[C Language Brush Questions] Three Questions for Getting Started with Pointers | String Length, String Copy, Two Number Swap
2022-08-02 19:06:00 【No. 7 Andy】
作者:柒号华仔
个人主页:欢迎访问我的主页
个人信条:星光不问赶路人,岁月不负有心人.
个人方向:主要方向为5G,同时兼顾其他网络协议,编解码协议,C/C++,linux,云原生等,感兴趣的小伙伴可以关注我,一起交流.
推荐一款模拟面试、刷题神器:*登录免费刷题
目录
前言
Brought it to my friends todayC语言刷题,一起刷题,Let's go through customs and interview together to enter the big factory,At the same time, brushing the questions is also reinforcement learning,The only way to consolidate knowledge.
The title comes from Niuke Tiba of Niuke.com,链接为:Click to jump to brush the artifact.经典高频面试题,应有尽有,各种编程语言,一网打尽.努力吧,我们都是赶路人!

)
CC1 获取字符串长度
1.1 题目描述
描述
键盘输入一个字符串,编写代码获取字符串的长度并输出,要求使用字符指针实现.
输入描述:
键盘输入一个字符串
输出描述:
输出字符串的长度
示例
输入: helloworld
输出: 10
1.2 题目解析
After the program reads the keyboard input string,字符串以’\0’作为结束符号,Use a pointer to point to this array of strings,Accumulate the length of the string by shifting the pointer,直到碰见’\0’结束.
1.3 代码实现
#include<stdio.h>
#include<string.h>
int main(void)
{
char a[64];
gets(a);
char *start=a;
char *end=a;
while(*end!='\0'){
end++;
}
printf("%d",end-start);
return 0;
}
CC2 复制部分字符串
2.1 题目描述
描述
键盘输入一个长度为len(1 <= len < 30)的字符串,再输入一个正整数 m(1 <= m <= len),将此字符串中从第 m 个字符开始的剩余全部字符复制成为另一个字符串,并将这个新字符串输出.要求用指针处理字符串.
输入描述:
键盘输入一个长度为len(1 <= len < 30)的字符串,再输入一个正整数 m(1 <= m <= len)
输出描述:
输出复制的新字符串
示例
输入: helloworld 6
输出: world
2.2 题目解析
When solving the problem, pay attention to entering the string first,Then enter the first few characters to start copying.数组是从0开始,因此mIt needs to be subtracted by one to start the calculation.The title requires processing with pointers,Arrays are not allowed.
2.3 代码实现
#include <stdio.h>
#include <string.h>
int main() {
char s[30] = {
0 };
gets(s);
int m = 0;
scanf("%d", &m);
char *p = &s[m - 1];
int n = strlen(s);
for (int i = 1; i < n - m + 1; i++) {
printf("%c", *(p + i));
}
return 0;
}
CC3 编写函数实现两数交换(指针方式)
3.1 题目描述
描述
编写一个函数,实现两个整数的交换,要求采用指针的方式实现.
输入描述:
键盘输入2个整数 m 和 n
输出描述:
输出交换后m 和 n 的值,中间使用空格隔开
示例
输入: 2 3
输出: 3 2
3.2 题目解析
The first thing to note is the use of pointers,为了实现交换,We need to define an intermediate volume for transition transformations.
3.3 代码实现
#include <stdio.h>
int main()
{
int m=0,n=0,temp=0;
int* pm=&m;
int* pn=&n;
int* pt=&temp;
scanf("%d\n%d",pm,pn);
*pt=*pm;
*pm=*pn;
*pn=*pt;
printf("%d %d\n",m,n);
return 0;
}
结语
纸上得来终觉浅,绝知此事要躬行,C语言的学习还是得基础知识+Do-it-yourself synchronization,Find a website where you can practice online,比如牛客网,多多练习,假以时日,Believe that the gains are huge,进步神速!
边栏推荐
猜你喜欢

numpy的学习笔记

总结嵌入式C语言难点 (1部分) 【结尾有资料】

互联网刚需岗位 前景一片大好?

2.NVIDIA Deepstream开发指南中文版--自述文件

Oracle 11 g rac finished patch, dbca new patches of SQL database also needs to perform?

MYSQL一站式学习,看完即学完

持续集成(三)Jenkins新增节点

金仓数据库 OCCI 迁移指南(4. KingbaseES 的 OCCI 迁移指南)

【Redis】连接报错:Could not connect to Redis at 127.0.0.1:6379: Connection refused

Antd-ProComponents中的EditableProTable无法在子行继续新增子子行的临时解决方案
随机推荐
工信部电子五所张志强:中国数据库行业发展趋势分析
默认用户名和密码(SQL)
mysql 《一》触发器
乌总统解除乌克兰国家安全局信息和情报分析部负责人职务
Special Variables (SQL)
SQL语句基础
[LeetCode]剑指 Offer 32 - II. 从上到下打印二叉树 II
Inconsistency between oracle and mysql statement results
2022年PMP考试应该注意些什么?
实时数仓架构演进及选型
js通过两种方式进行对商品价格排序
数字孪生园区场景中的坐标知识
2.NVIDIA Deepstream开发指南中文版--自述文件
智能合约安全——delegatecall (1)
jar包应用的简单启停脚本
排查生产环境:MySQLTransactionRollbackException数据库死锁
Nacos环境隔离
【二】TS基本类型
[LeetCode]剑指 Offer 55 - I. 二叉树的深度
julia系列6:并行计算