CC++C++11C++14C++17Learn C++Syntax

What Is typedef In C++

What Is typedef In C++

C++ language is an evolved version of the C language. In development, the most commonly used features and functions in C++ come, at least in part, from the C language. One of these C-based features is the typedef specifier. While there is a type alias in C++ typedef is still a strong feature which allows us to create abbreviations for long types. In this article, we will explain how to use typedef in C++, there are also examples that can be used by a professional C++ Compiler.

What Is typedef In C++

The typedef specifier is used in a declaration of a new type, generally, it is an abbreviation or simplification of an existing type. The typedef name is used to create an alias term that can be used anywhere in coding to define existing data types, user-defined data types, and pointers. Typedef allows us to give descriptive names to standard data types, that can be used to help developers, as a self-documenting code. Typedef aliases are very useful when the predefined name is too long or complex to write again and again. The typedef specifier is generally used at the start of coding or used in headers.

What is the syntax for using typdef in C++?

The typedef syntax is as follows:

Note that, a typedef specifier cannot be used in the declaration of a function parameter nor in the decl-specifier-seq of a function definition.

For example, we can create a new ULINT alias for the long long int as below,

then, we can use our new alias as below,

this is same as:

typedef can be used with struct declarations and other declarations too.

Is there a simple example of how to use typedef in C++?

Here is a simple example that shows how we can use typedef to create a new alias.

Here is another example that shows how we can use typedef to create a new alias of a struct.

In modern C++, there is also a type alias. We have more articles about type alias as described below.

What is type alias in C++ is it an alternative to typedef in C++?

Type Alias is a term that refers to a previously defined types, alias declaration can be used to declare a name to use as a synonym for a previously declared type. We use using declaration (using-declaration) to declare a type alias, and it is effectively the same as typedef

If you are looking how to use alias template please use this dynamic search: https://learncplusplus.org/tag/alias-template/. For more information about alias template feature, please see Alias templates Proposal document.

Learn How To Use Type Alias In C++ the C++ Builder Logo

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++

Learn Copy Constructors in C++ Classes

C++C++11C++14C++17Introduction to C++Learn C++Syntax

Learn How To Use Types Of Destructors In C++?

C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

C++C++11C++14C++17C++20Introduction to C++Learn C++

How To Learn The Move Constructors In Modern C++?