Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/language/basic concepts"

From cppreference.com
< cpp‎ | language
(refined pre-c++14 definition of "variable")
m (fmt)
 
(43 intermediate revisions by 28 users not shown)
Line 4: Line 4:
 
This section provides definitions for the specific terminology and the concepts used when describing the C++ programming language.
 
This section provides definitions for the specific terminology and the concepts used when describing the C++ programming language.
  
A C++ program is a sequence of text files (typically header and source files) that contain {{rlp|declarations}}. They undergo {{rlp|translation phases|translation}} to become an executable program, which is executed when the OS calls its {{rlp|main function}}.
+
A C++ program is a sequence of text files (typically header and source files) that contain {{rlp|declarations}}. They undergo {{rlp|translation phases|translation}} to become an executable program, which is executed when the C++ implementation calls its {{rlp|main function}}.
  
Certain words in a C++ program have special meaning, and these are known as [[cpp/keyword|keywords]]. Others can be used as {{rlp|identifiers}}. [[cpp/comment|Comments]] are ignored during translation. Certain characters in the program have to be represented with {{rlp|escape|escape sequences}}.
+
Certain words in a C++ program have special meaning, and these are known as [[cpp/keyword|keywords]]. Others can be used as {{rlp|identifiers}}. [[cpp/comment|Comments]] are ignored during translation. C++ programs also contain {{rlpsd|expressions#Literals}}, the values of characters inside them are determined by {{rlp|charset|character sets and encodings}}. Certain characters in the program have to be represented with {{rlp|escape|escape sequences}}.
  
The ''entities'' of a C++ program are values, {{rlp|objects}}, {{rlp|reference}}s{{rev inl|since=c++17|, {{rlp|structured binding}}s}}, {{rlp|functions}}, {{rlp|enum|enumerators}}, {{rlp|type}}s, class members, {{rlp|templates}}, {{rlp|template specialization}}s, {{rlp|namespace}}s, and {{rlp|parameter pack}}s. Preprocessor [[cpp/preprocessor/replace|macros]] are not C++ entities.
+
The ''entities'' of a C++ program are values, {{rlp|objects}}, {{rlp|reference}}s{{rev inl|since=c++17|, {{rlp|structured binding}}s}}, {{rlp|functions}}, {{rlp|enum|enumerators}}, {{rlp|type}}s, class members, {{rlp|templates}}, {{rlp|template specialization}}s{{rev inl|since=c++11|, {{rlp|parameter pack}}s}}, and {{rlp|namespace}}s. Preprocessor [[cpp/preprocessor/replace|macros]] are not C++ entities.
  
Entities are introduced by {{rlp|declarations}}, which associate them with {{rlp|name}}s and define their properties. The declarations that define all properties required to use an entity are {{rlp|definition}}s. A program must contain only one definition of any non-inline function or variable that is {{rlp|definition|odr-used}}.  
+
''{{rlp|declarations|Declarations}}'' may introduce entities, associate them with {{rlp|name}}s and define their properties. The declarations that define all properties required to use an entity are {{rlp|definition}}s. A program must contain only one definition of any non-inline function or variable that is {{rlp|definition#ODR-use|odr-used}}.
  
Definitions of functions include sequences of {{rlp|statements}}, some of which include {{rlp|expressions}}, which specify the computations to be performed by the program.
+
Definitions of functions usually include sequences of {{rlp|statements}}, some of which include {{rlp|expressions}}, which specify the computations to be performed by the program.
  
 
Names encountered in a program are associated with the declarations that introduced them using {{rlp|lookup|name lookup}}. Each name is only valid within a part of the program called its {{rlp|scope}}. Some names have {{rlp|storage duration|linkage}} which makes them refer to the same entities when they appear in different scopes or translation units.
 
Names encountered in a program are associated with the declarations that introduced them using {{rlp|lookup|name lookup}}. Each name is only valid within a part of the program called its {{rlp|scope}}. Some names have {{rlp|storage duration|linkage}} which makes them refer to the same entities when they appear in different scopes or translation units.
Line 18: Line 18:
 
Each object, reference, function, expression in C++ is associated with a {{rlp|type}}, which may be {{rlp|types|fundamental}}, compound, or {{rlp|classes|user-defined}}, complete or {{rlp|incomplete type|incomplete}}, etc.
 
Each object, reference, function, expression in C++ is associated with a {{rlp|type}}, which may be {{rlp|types|fundamental}}, compound, or {{rlp|classes|user-defined}}, complete or {{rlp|incomplete type|incomplete}}, etc.
  
{{rrev multi|until1=c++14
+
Declared objects and declared references that are not {{rlp|data members|non-static data members}} are ''variables''.
|rev1=Named objects, and named references that are not {{rlp|data members|non-static data members}}, are ''variables''.
+
|rev2=Declared objects, and declared references that are not non-static data members, are ''variables'', whether named or unnamed.
+
}}
+
  
 
===See also===
 
===See also===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc see c | c/language/basic_concepts | Basic concepts}}
+
{{dsc see c|c/language/basic_concepts|Basic concepts|nomono=true}}
 
{{dsc end}}
 
{{dsc end}}
  
{{langlinks|zh}}
+
{{langlinks|es|ja|ko|ru|zh}}

Latest revision as of 17:29, 23 January 2024

 
 
C++ language
General topics
Flow control
Conditional execution statements
if
Iteration statements (loops)
for
range-for (C++11)
Jump statements
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications (until C++17*)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
const/volatile
decltype (C++11)
auto (C++11)
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Memory allocation
Classes
Class-specific function properties
explicit (C++11)
static

Special member functions
Templates
Miscellaneous
 
 

This section provides definitions for the specific terminology and the concepts used when describing the C++ programming language.

A C++ program is a sequence of text files (typically header and source files) that contain declarations. They undergo translation to become an executable program, which is executed when the C++ implementation calls its main function.

Certain words in a C++ program have special meaning, and these are known as keywords. Others can be used as identifiers. Comments are ignored during translation. C++ programs also contain literals, the values of characters inside them are determined by character sets and encodings. Certain characters in the program have to be represented with escape sequences.

The entities of a C++ program are values, objects, references, structured bindings(since C++17), functions, enumerators, types, class members, templates, template specializations, parameter packs(since C++11), and namespaces. Preprocessor macros are not C++ entities.

Declarations may introduce entities, associate them with names and define their properties. The declarations that define all properties required to use an entity are definitions. A program must contain only one definition of any non-inline function or variable that is odr-used.

Definitions of functions usually include sequences of statements, some of which include expressions, which specify the computations to be performed by the program.

Names encountered in a program are associated with the declarations that introduced them using name lookup. Each name is only valid within a part of the program called its scope. Some names have linkage which makes them refer to the same entities when they appear in different scopes or translation units.

Each object, reference, function, expression in C++ is associated with a type, which may be fundamental, compound, or user-defined, complete or incomplete, etc.

Declared objects and declared references that are not non-static data members are variables.

[edit] See also

C documentation for Basic concepts