This is the seventh day of my participation in the More text Challenge. For details, see more text Challenge


The first C++ program

#include <iostream>
int main(a)
{
    std::cout << "First day of learning C++ in Hello system! \n";
}
Copy the code

annotation

A single
// Note the content
Copy the code
Multiple lines
/* Comments */
Copy the code

Variables and Constants

#include <iostream>
/ / macro constants
#define MAX 0x3f3f3f3f3f
// Const modifier
const long long MAXX = 0x3f3f3f3f3f;
int main(a)
{
    /// Variable definition
    int a = 5;
    std::cout << MAX<<""<<MAXX<<""<<a<<endl;
}
Copy the code

Name of identifier

1.The identifier cannot be a keyword2.Contains only letters, numbers, and understrokes3.The first character can only be a letter or an underscore4.Letters are case sensitive5.Be recognizable and readable* / / * proposal
Copy the code

The data type

Introduction to the
When programming in a programming language, a variety of variables are used to store information. A variable retains the memory location of the value it stores. This means that when you create a variable, some space is left in memory. You may need to store information of various data types (such as character, wide character, integer, floating point, double floating point, Boolean, etc.), and the operating system allocates memory and decides what to store in reserved memory based on the data types of variables.Copy the code
type The keyword
The Boolean bool
character char
The integer int
floating-point float
Double floating point double
No type void
Wide character type wchar_t
Actually,wchar_tHere's how it came to be:typedef short int wchar_t; sowchar_tThe actual space is the sumshort intThe same. Some basic types can be modified with one or more type modifiers:signed
unsigned
short
longThe following table shows how much memory each variable type requires to store a value in memory, and the maximum and minimum values that a variable of that type can store. Note: this may vary by system, but one byte is8position Note:long intintAre all4Bytes, because early C compilers definedlong intTake up4Bytes,intTake up2The new version of the C/C++ standard is compatible with the earlier setting.Copy the code
The integer
Short integer
short num1 = 22; The number of bytes:2Scope:- 32768.~32767  2 -^15~2^15
Copy the code
The integer
int	num1 = 44444The number of bytes:4Scope:- 2147483648. ~ 2147483647  2 -^31~2^31
Copy the code
Long integer
long num = 444The number of bytes:4Scope:- 2147483648. ~ 2147483647  2 -^31~2^31
Copy the code
Long integer
long long num = 4444The number of bytes:8Scope:- 9223372036854775808.9223372036854775807   2 -^63~2^63
Copy the code
Unsigned integer
unsigned int = 123; Number of bytes: 4 Range: 0 to 4294967295 0 to 2^32 Other type type, the negative range is added to the positive range.Copy the code
Keywords – sizeof
#include<iostream>  
#include <limits>
 
using namespace std;  
  
int main(a)  
{  
    cout << "type: \t\t" << "************size**************"<< endl;  
    cout << "bool: \t\t" << Number of bytes: << sizeof(bool);  
    cout << "\t Max:" << (numeric_limits<bool>::max)();  
    cout << "\t\t minimum:" << (numeric_limits<bool>::min)() << endl;  
    cout << "char: \t\t" << Number of bytes: << sizeof(char);  
    cout << "\t Max:" << (numeric_limits<char>::max)();  
    cout << "\t\t minimum:" << (numeric_limits<char>::min)() << endl;  
    cout << "signed char: \t" << Number of bytes: << sizeof(signed char);  
    cout << "\t Max:" << (numeric_limits<signed char>::max)();  
    cout << "\t\t minimum:" << (numeric_limits<signed char>::min)() << endl;  
    cout << "unsigned char: \t" << Number of bytes: << sizeof(unsigned char);  
    cout << "\t Max:" << (numeric_limits<unsigned char>::max)();  
    cout << "\t\t minimum:" << (numeric_limits<unsigned char>::min)() << endl;  
    cout << "wchar_t: \t" << Number of bytes: << sizeof(wchar_t);  
    cout << "\t Max:" << (numeric_limits<wchar_t>::max)();  
    cout << "\t\t minimum:" << (numeric_limits<wchar_t>::min)() << endl;  
    cout << "short: \t\t" << Number of bytes: << sizeof(short);  
    cout << "\t Max:" << (numeric_limits<short>::max)();  
    cout << "\t\t minimum:" << (numeric_limits<short>::min)() << endl;  
    cout << "int: \t\t" << Number of bytes: << sizeof(int);  
    cout << "\t Max:" << (numeric_limits<int>::max)();  
    cout << "\t minimum:" << (numeric_limits<int>::min)() << endl;  
    cout << "unsigned: \t" << Number of bytes: << sizeof(unsigned);  
    cout << "\t Max:" << (numeric_limits<unsigned>::max)();  
    cout << "\t minimum:" << (numeric_limits<unsigned>::min)() << endl;  
    cout << "long: \t\t" << Number of bytes: << sizeof(long);  
    cout << "\t Max:" << (numeric_limits<long>::max)();  
    cout << "\t minimum:" << (numeric_limits<long>::min)() << endl;  
    cout << "unsigned long: \t" << Number of bytes: << sizeof(unsigned long);  
    cout << "\t Max:" << (numeric_limits<unsigned long>::max)();  
    cout << "\t minimum:" << (numeric_limits<unsigned long>::min)() << endl;  
    cout << "double: \t" << Number of bytes: << sizeof(double);  
    cout << "\t Max:" << (numeric_limits<double>::max)();  
    cout << "\t minimum:" << (numeric_limits<double>::min)() << endl;  
    cout << "long double: \t" << Number of bytes: << sizeof(long double);  
    cout << "\t Max:" << (numeric_limits<long double>::max)();  
    cout << "\t minimum:" << (numeric_limits<long double>::min)() << endl;  
    cout << "float: \t\t" << Number of bytes: << sizeof(float);  
    cout << "\t Max:" << (numeric_limits<float>::max)();  
    cout << "\t minimum:" << (numeric_limits<float>::min)() << endl;  
    cout << "size_t: \t" << Number of bytes: << sizeof(size_t);  
    cout << "\t Max:" << (numeric_limits<size_t>::max)();  
    cout << "\t minimum:" << (numeric_limits<size_t>::min)() << endl;  
    cout << "string: \t" << Number of bytes: << sizeof(string) << endl;  
    / / < < "\ t Max:" < < (numeric_limits < string > : : Max) is () < < "\ t the minimum:" < < (numeric_limits < string > : : min) () < < endl;
    cout << "type: \t\t" << "************size**************"<< endl;  
    return 0;  
}
Copy the code