typedef简化
/***
mystrcat:
***/
#include<stdio.h>
#include<string.h> char *mystrcat(char *s1,char *s2)
{
strcat(s1,s2);
return s1;
} int main()
{
char s1[] = "hello";
char s2[] = " world";
char *s = mystrcat(s1,s2);
printf("s = %s\n",s);
return ;
}
指向函数的指针:
#include<stdio.h>
#include<string.h> char *mystrcat(char *s1,char *s2)
{
strcat(s1,s2);
return s1;
} char *test(char *(*p)(char *,char *),char *s1,char *s2)
{
return p(s1,s2);
} int main()
{
char s1[] = "hello";
char s2[] = " world";
//char *s = mystrcat(s1,s2);
char *s = test(mystrcat,s1,s2);
printf("s = %s\n",s);
return ;
}
typedef简化:
#include<stdio.h>
#include<string.h> char *mystrcat(char *s1,char *s2)
{
strcat(s1,s2);
return s1;
} typedef char*(*STRCAT)(char *,char *); char *test(STRCAT p,char *s1,char *s2)
{
return p(s1,s2);
} int main()
{
char s1[] = "hello";
char s2[] = " world";
//char *s = mystrcat(s1,s2);
char *s = test(mystrcat,s1,s2);
printf("s = %s\n",s);
return ;
}
typedef简化的更多相关文章
- C/C++函数指针(typedef简化定义)
学习要点: 1,函数地址的一般定义和typedef简化定义; 2,函数地址的获取; 3,A函数地址作为B函数参数的传递; 函数存放在内存的代码区域内,它 ...
- typedef 与指针、多维数组
1.在typedef中使用指针往往会带来意外的结果.如下: typedef string *pstring; const pstring cstr; 绝大数人刚开始都会认为cstr是一种指针,它指向c ...
- 函数指针与指针函数以及typedef
c难于理解的是指针,其魅力之处也是指针,函数方法结构,化繁为简可以理解为:返回值 函数名(形参表),具体来说: 返回值:1.可以为空void 2.基本数据类型char short int long f ...
- typedef与define基本使用
参考: typedef用法 http://www.cnblogs.com/ggjucheng/archive/2011/12/27/2303238.html#define用法:http://blog. ...
- C 中typedef 函数指针的使用
类型定义的语法可以归结为一句话:只要在变量定义前面加上typedef,就成了类型定义.这儿的原本应该是变量的东西,就成为了类型. int integer; //整型变量int *pointer ...
- const和typedef的常见用法详解
一.说说const 一般而言,const主要是用来防止定义的对象再次被修改,定义对象变量时要初始化变量. 常见用法如下: 1.用于定义常量变量,这样这个变量在后面就不可以再被修改 const int ...
- C中typedef 函数指针的使用
类型定义的语法可以归结为一句话:只要在变量定义前面加上typedef,就成了类型定义.这儿的原本应该是变量的东西,就成为了类型. int integer; //整型变量int *pointer ...
- 基于typedef的用法详解【转】
也许新手用这个关键字不多,但它却是一个很有用的关键字,可以使代码模块化程度更好(即与其它代码的关联较少),在C++中还是实现Traits技术的基础,也是模板编程的基本语法之一. 若说变量定义是为变量命 ...
- C++typedef的详细用法
转自知乎的一段解释: 作者:知乎用户链接:https://www.zhihu.com/question/29798061/answer/144423125来源:知乎著作权归作者所有.商业转载请联系作者 ...
随机推荐
- 2 - sat 模板(自用)
2-sat一个变量两种状态符合条件的状态建边找强连通,两两成立1 - n 为第一状态(n + 1) - (n + n) 为第二状态 例题模板 链接一 POJ 3207 Ikki's Story IV ...
- nnginx配置代理服务器
因为有些服务有ip白名单的限制,部署多节点后ip很容易就不够用了,所以可以将这些服务部署到其中的一些机器上, 并且部署代理服务器,然后其余机器以代理的方式访问服务.开始是以tinyproxy作为代理服 ...
- 使用Enablebuffering多次读取Asp Net Core 请求体
使用Enablebuffering多次读取Asp Net Core 请求体 1 .Net Core 2.X时代 使用EnableRewind倒带 public IActionResult Index( ...
- 树莓派3B+和3B 安装64位debian GUN/Linux系统
请直接参考如下博客: https://blog.csdn.net/u013451404/article/details/80710136 如果是3B的树莓派用户,只需要把第一个分区boot里的.dtb ...
- C#:Guid.NewGuid()和DateTime.Now该选择哪个???
直接上代码: namespace ConsoleApp1 { class Program { static void Main(string[] args) { Console.WriteLine(& ...
- O025、OpenStack 通用设计思路
参考https://www.cnblogs.com/CloudMan6/p/5427981.html API 前端服务 每个OpenStack组件可能包含若干子服务,其中必定有一个API服务负 ...
- python版本
一般在Linux下,默认会安装一个python2.*的版本,但是我们自己开发有时候需要python3.*的版本 1. 安装python3 .安装依赖包 )首先安装gcc编译器,gcc有些系统版本已经默 ...
- Java高并发程序设计学习笔记(三):Java内存模型和线程安全
转自:https://blog.csdn.net/dataiyangu/article/details/86412704 原子性有序性可见性– 编译器优化– 硬件优化(如写吸收,批操作)Java虚拟机 ...
- ASE19 团队项目 模型组 scrum report集合
scrum report 链接 scrum1 report scrum2 report scrum3 report scrum4 report scrum5 report scrum6 report ...
- Delphi 通过ADO连接数据库