`typedef` — C++ Keyword
`typedef` — C++ Keyword
The typedef keyword in C++: creates a type alias using the traditional C syntax.
`typedef` — C++ Keyword
The typedef keyword in C++: creates a type alias using the traditional C syntax.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
typedefCreates an alias for a type using the legacy C syntax. Prefer using (C++11) for new code, as using is more readable for complex types and supports templates.
typedef existing-type alias-name;
typedef return-type (*alias-name)(parameter-types); // function pointer alias
#include <print>
#include <vector>
// Simple type alias
typedef unsigned long ulong;
// Function pointer alias
typedef int (*BinaryOp)(int, int);
// Struct with typedef (common C pattern)
typedef struct { int x; int y; } Point;
int add(int a, int b) { return a + b; }
int main() {
ulong n = 1'000'000UL;
std::println("{}", n);
BinaryOp op = add;
std::println("{}", op(3, 4)); // 7
Point p = {1, 2};
std::println("{} {}", p.x, p.y);
}
typedef cannot be used directly; use using (alias template) instead.using ulong = unsigned long; is equivalent and clearer.typedefint main() {
// Pick one facility from this reference page.
// Write the smallest program that exercises its main precondition,
// complexity rule, or lifetime constraint before scaling up.
return 0;
}