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:

  1. Integer types: Used to represent whole numbers. The most common integer types in C++ are int, short, long, and long long.

  2. Floating-point types: Used to represent real numbers with fractional parts. The two main floating-point types in C++ are float and double.

  3. Character types: Used to represent characters. The two main character types in C++ are char and wchar_t.

  4. Boolean type: Used to represent true or false values. The boolean type in C++ is bool.

  5. 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.

  6. Enumeration types: Used to define a set of named constants. Enumeration types in C++ are defined using the enum keyword.

  7. 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
*/
posted @   SpacetimeCoding  阅读(14)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示