C--typedef 给数据类型起新名字

#include <stdio.h>
//给结构体起个新名字stu 
typedef struct student {
        char name[50];
        int age;
        int achievement;
    } stu;
    //student 可以不要
    //新名字的好处,使用时简洁 

int main ()
{
   
    typedef int Length;//给数据类型起个新名字
    //给int起个新名字 Length
    stu d;
    
           
   
   return(0);
}
#include <iostream>
#include <typeinfo> 

int main(){
    typedef int* pint;  //给int*起个别名pint
    
    int a=10;
    pint p=&a;
    
    

std::cout<<p<<std::endl;
std::cout<<*p<<std::endl;
    
}
#include <iostream>
using namespace std;

int add(int a, int b)
{
return a + b;
}
int sub(int a, int b)
{
return a - b;
}

typedef int(*pfunc)(int a, int b);//声明函数指针数据类型

int main()
{
//方法一
int(*p)(int, int) = add; //定义了一个函数指针
//格式:返回类型 (*指针变量名)(参数列表);
int x = p(100, 10);//利用指针调用函数

//方法二
pfunc pf;//创建一个函数指针
pf = sub; //使函数指针指向add函数
x = pf(20, 30);

printf("%d
", x);
return(0);
}

原文地址:https://www.cnblogs.com/liming19680104/p/13374912.html