数据变量的别名

|   版权声明:本文为博主原创文章,未经博主允许不得转载。

  在C++中我们有很多的数据类型,如简单数据类型包括int,long,double,float,char等等,复杂的数据类型也有struct结构体,class类,联合体等等。一般平常我们定义数据类型都是通过关键字进行声明,那么我们在C++和C中给数据变量起别名,通过别名来定义变量,下面有两种的给数据类型起别名的方法。

  (1)、通过typedef关键字:

#include <iostream>
using namespace std;

typedef int Integer;

int main(void)
{
	Integer a, b;
	cin >> a >> b;
	cout << "a+b= " << a + b << endl;
	return 0;
}

  

  (2)、通过struct

#include <iostream>
using namespace std;

typedef struct Node
{
	struct Node *next;
	char data;
}ListNode;

ListNode* initList(ListNode** head, char data)
{
	//....
	//上面已经通过ListNode来实现变量的声明,链表的具体操作请看博客分类数据结构--单向链表

	return *head;
}

  单向链表:http://www.cnblogs.com/geore/p/5791520.html

---------如有错误,希望大家多多指正---------

原文地址:https://www.cnblogs.com/geore/p/5822665.html