C++11 constant expression#define_crt_secure_no_warnings#include#includestring>#include#include/** Constant expression is primarily to allow some computations to occur at compile time, that is, when code is compiled rather than running. * This is a
Original address: http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.28This is my translation for the time being.A constant expression is an expression that represents a basic data type or a string data type, and is a value that can
Const Constants
Definition can not be modified, so the definition must be initialized : const std::string hi = "hello!"; Const Object Scope
Non-const objects defined in the global scope can be accessed throughout the program, and extern is the
I. CONSTEXPR and constant expressionsConstant expressions (const expression) are expressions that do not change the value and can be evaluated in the compilation process. Obviously, literals are constant expressions, and const objects initialized
constexpr functionconstexpr function: The constexpr function refers to a function that is used for a constant expression, the return value type of the function, and all parameter types must be literal, and the function must have only one return
C ++ const qualifier
Const qualifier:Use const to restrict objects so that the value of a const object cannot be changed once it is created.
When defining a const object, you must initialize it in either of the following ways:
const int x = 10;
Switch-case retrun break, switch-caseretrun
{
If statements process two branches, the if-else-if structure must be used when processing multiple branches. However, if there are many branches, the more nested if statement layers, the program is not
Contexpr and constant expressionscontexpr function[test1.cpp]1#include 2 using namespacestd;3 4constexprintScreenintX//constexpr5 {6 returnx;7 }8 9 intMain ()Ten { One Const intx =0;//Const, which is a constant expression because the value
1, initialization
The const object must be initialized if its value cannot be changed once it is created.
The initial value can be arbitrarily complex expressions:
const int i = Get_size (); Correct: run-time initialization
const INT j= 42; Correct,
The C language does not limit the number of branches that if else can handle, but when there are too many branches, it is not convenient to use if else, and it is easy to have an if else pairing error. For example, enter an integer that outputs the
Const qualifier: Use const to qualify the object so that the const object cannot be changed once it is created.A const object must be initialized when it is defined, in two ways:const int x = 10;const int x = GetValue ();The first is to assign a
◇ Design of selection structure1.if statement:The IF statement is the simplest and most intuitive way to implement a selection statement. His simple form is to determine if a condition value is true and, if true, to execute a piece of code.if
Assertions and user-supplied messagesthe C + + language supports the three error-handling mechanisms that help you debug your application: #error directives, static_assert keywords, and assert (CRT) macros. All three mechanisms emit error messages,
C ++ Primer Reading Notes 1
1. In Windows, enter the file Terminator As Ctrl + Z.
2. How do I select a type?
1) Use an unsigned type when youknow that the values cannot be negative
2) Use int for integer arithmetic. short is usually too small and,
1. OverviewRecently in See C + + Primer5 just see half, summed up c++11 inside did add a lot of new things, if there is no understanding, don't say you write, see others write code estimates will be a bit difficult. C + + Primer5 is a relatively
A value of a shape such as 42 is called a literal constant. The form and value of a literal constant determines the type of the constant. For example, 0x42 is an integer constant of 16 binary representations. ' A ' is a char literal. Literal
C ++ templates fall into two categories:1. Function TemplateFormat: template Reverse type function name (parameter list) {function body}For example:Template void swap (T & a, T & B ){} Call time:Int a, B;Swap (a, B ); Double d1, d2;Swap (d1, d2 );
1. Knowledge Points:(1) Character typeChar ch;(Ch >= ' a ' && ch = ' A ' && ch (Ch >= ' 0 ' && ch • Character type dataCharacter variable: char ch; (defines the character variable ch for storing character data.) )Character constant: ' A ' z ' ' a '
1. The so-called programming is to send a command to the computer, using a paragraph, or a few commands to let the computer do what you want it to do.2. The so-called object is the object you want it to do things, just like you want Michael to buy
2.9 Writing your own header fileObjective
To allow the program to be separated into separate logical blocks, C + + supports the so-called separate compilation
The program can consist of multiple files
2.9.1
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.