what are the primitive types of C++?
In C++, there are several primitive data types, which are also known as fundamental or built-in data types. These include:
-
Integer types: Used to represent whole numbers. The most common integer types in C++ are int, short, long, and long long.
-
Floating-point types: Used to represent real numbers with fractional parts. The two main floating-point types in C++ are float and double.
-
Character types: Used to represent characters. The two main character types in C++ are char and wchar_t.
-
Boolean type: Used to represent true or false values. The boolean type in C++ is bool.
-
Void type: Used to indicate a lack of a return value. The void type in C++ is used for functions that do not return a value.
-
Enumeration types: Used to define a set of named constants. Enumeration types in C++ are defined using the enum keyword.
-
Pointer types: Used to store memory addresses. Pointer types in C++ are defined using the * operator.
These primitive types are used to build more complex data structures and functions in C++. It's important to understand these types and how they work to write efficient and effective code in C++.
#include <iostream> using namespace std; int main() { cout << sizeof(bool) << endl; cout << sizeof(short) << endl; cout << sizeof(int) << endl; cout << sizeof(long) << endl; cout << sizeof(float) << endl; cout << sizeof(double) << endl; cout << sizeof(long double) << endl; cout << sizeof(long long) << endl; cout << sizeof(char *) << endl; return 0; } // Outputs /* 1 2 4 4 4 8 8 8 8 */
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现