C&c++--c and C + + knowledge points

Source: Internet
Author: User
Tags integer numbers strcmp volatile

One of the C + + Knowledge Points series (go + organize)

Do not forget to add a semicolon after the class declaration, otherwise there will be many errors!!


One of the C series
One, #include "filename.h" and the difference between #include<filename.h>
#include "filename.h" means that the compiler will find this file starting from the current working directory
#include <filename.h> means that the compiler will start looking for this file from the standard library directory

Second, the role of the head file
Enhanced safety testing
It is possible to easily invoke library functionality through a header file without having to care about how it is implemented

Three, *, & modifier position
For the * and & modifiers, it is best to close the modifier to the variable name in order to avoid misunderstandings

Iv. If statement
Do not compare Boolean variables with any values, which can be very error-prone.
Shaping variables must be compared with values of the same type
Floating-point variables are best less than points, even if they have a value to limit.
Pointer variables are compared to NULL, not to Boolean and reshape

V. Comparison of Const and # define
Const has a data type, #define没有数据类型
The const in the individual compiler can be debugged, #define不可以进行调试
There are two ways of defining constants in a class
1, in the class in the declaration constant, but does not assign the value, in the constructor initialization table to assign the value;
2. Use enumerations instead of const constants.

Vi. how values are passed in C + + functions
There are three ways: value passing (pass by value), pointer passing (pass by pointer), reference passing (pass by reference)
void Fun (char c)//pass by value
void Fun (char *str)//pass by pointer
void Fun (char &str)//pass by reference
If input parameters are passed as values, it is best to use reference passing instead, because reference passing eliminates the construction and destruction of temporary objects
The type of the function can not be omitted, even if there is no need to add a void

The pointer or reference constant in the function body cannot be returned
Char *func (void)
{
Char str[]= "Hello Word";
This cannot be returned because STR is a specified variable, not a normal value, and will be written off after the function is finished.
return str;
}
Pointer variables in a function body do not automatically release as the function dies

Implementation of 八、一个 memory copy function
void *memcpy (void *pvto,const void *pvfrom,size_t size)
{
ASSERT ((pvto!=null) && (pvfrom!=null));
Byte *pbto= (byte*) pvto; Prevent the address from being changed
Byte *pbfrom= (byte*) Pvfrom;
while (size-->0)
pbto++ = pbform++;
return pvto;
}

Nine, the memory allocation method
There are three ways to assign, remember, maybe someone will ask you that question when you go to the interview that day.
1, static storage, is at the time of the program compile has been allocated well, during the entire run, such as global variables, constants.
2, the allocation of the stack, the local variables within the function is allocated from this, but the allocation of memory is easy to be limited.
3, heap allocation, also known as dynamic allocation, such as we use New,malloc to allocate memory, with Delete,free to release memory.

Ten, memory allocation considerations
When allocating memory with new or malloc, you must assign an initial value to this pointer.
After releasing memory with delete or free, you must point the pointer to null
Pointer data to a constant cannot be modified

XI. content Replication and comparison
Array......
Char a[]= "Hello word!";
Char b[10];
strcpy (B,a);
if (strcmp (A, b) ==0)
{}
Pointer......
Char a[]= "Hello word!";
Char *p;
P=new Char[strlen (a) +1];
strcpy (P,a);
if (strcmp (p,a) ==0)
{}

12, the problem of sizeof
Remember that C + + cannot know the size of the object The pointer refers to, and the size of the pointer is always 4 bytes
Char a[]= "Hello world!"
Char *p=a;
count<<
count<<
Also, in the function, the array parameter is degraded to a pointer, so the following content is always output as 4
void Fun (char a[1000])
{
count<<
}

13. About Pointers
1. The pointer must be initialized when it is created
2. The pointer must be null after free or delete
3, the length of the pointer is 4 bytes
4, when releasing memory, if it is an array pointer, you must release all the memory, such as
Char *p=new char[100];
strcpy (P, "Hello World");
delete []p; Note the previous [] number
P=null;
5. The contents of an array pointer cannot exceed the maximum ease of array pointers.
Such as:
Char *p=new char[5];
strcpy (P, "Hello World"); Error target not big enough
delete []p; Note the previous [] number
P=null;

14, about Malloc/free and New/delete
The Malloc/free is a c/c+ memory-allocation character, and New/delete is a C + + memory specifier.
Note: Malloc/free is a library function, New/delete is an operator
Malloc/free cannot execute constructors and destructors, and New/delete can
New/delete can't run on C, so Malloc/free can't be eliminated.
Both must be used in pairs
You can use the _set_new_hander function to define the handling of memory allocation exceptions in C + +

XV, C + + features
New additions to C + + are overloaded (overload), inline (inline), const,virtual four kinds of mechanisms
Overloads and inline: can be used for global functions, or for member functions of classes;
Const and virtual: can only be used for class member functions;
Overloading: A function with the same name as the function in the same class. The function is called by different parameters. The function may not have the virtual keyword. Functions with the same name as global functions are not called overloads. If you call a global function with the same name in a class, you must use the global reference symbol:: Reference.

Overrides refer to a derived class function overriding a base class function
Function name is the same;
the same parameters;
The base class function must have the virtual keyword;
Different scopes (derived classes and base classes).

Hidden refers to the same function with the same name as a derived class that masks the base class
1, the function name is the same, but the parameters are different, at this time regardless of the base class has the virtual keyword, the base class function will be hidden.
2, the function name is the same, the parameters are the same, but the base class no virtual keyword (there is overwrite), the base class function will be hidden.

Inline: The inline keyword must be placed with the definition body, not simply in the declaration.

Const:const is the abbreviation of constant, the meaning of "constant unchanged". The const-modified items are protected against accidental changes and can improve the robustness of the program.
1, parameters for input with the pointer-type parameters, plus the const can prevent accidental changes.
2. When making input parameters by the user type referenced by value, it is better to pass the value to the reference and add the Const keyword, which is to improve the efficiency. There is no need to do this if the data type is an internal type:
Change void func (a A) to void func (const a &a).
void func (int a) does not need to be changed to void func (const int &a);
3, the return value of the pointer type of the function plus const, will make the function return value can not be modified, the assigned variable can only be const type variable. such as: function const char*getstring (void); Char *str=getstring () will be faulted. and the const char *str=getstring () will be correct.
4, the const member function refers to the function body can only call the const member variable, improve the program's key strong. such as declaring the function int getcount (void) const, this function body can only call the const member variable.
Virtual: Virtual functions: Derived classes can be overridden by functions, pure virtual functions: Just an empty function, no function implementation body;

16. What is the role of extern "C"?
Extern "C" is a connection-exchange-specified symbol provided by C + + that tells C + + that this code is a C function. This is because C + + compiled library function name will become very long, inconsistent with C generation, resulting in C + + cannot directly call C function, plus extren "C", C + + can directly invoke C function.
Extern "C" is used primarily for referencing and exporting of regular DLL functions and for C + + or C-header files in C + +. Use the extern "C" keyword in front of you.

17. Constructors and destructors
The constructor of the derived class should call the constructor of the base class in the initialization table;
Destructors for derived and base classes should be added to the virtual keyword.
Do not underestimate the constructors and destructors, in fact, it is not easy to make up.
#include
Class Base
{
Public
Virtua ~base () {cout<< "~base" << end;}
};
Class Derived:public Base
{
Public
Virtua ~derived () {cout<< "~derived" << end;}
};
void Main (void)
{
Base * PB = new Derived; Upcast
Delete PB;
}
The output is:
~derived
~base
If the destructor is not virtual, the output is
~base

18, #IFNDEF/#DEFINE/#ENDIF有什么作用
Copying the header file is repeatedly referenced






C + + Knowledge Point Series II
1. Write a "standard" macro min, this macro enters two parameters and returns the smaller one.
#define MIN (A) (A) <= (B)? (A): (B))
This test is designed for the following purposes:
1) identifies the basic knowledge that # define is applied in the macro. This is very important. Because macros are the only way to generate embedded code before the embedded (inline) operator becomes part of standard C, embedding code is often a necessary method for embedded systems to achieve the required performance.
2) knowledge of the triple conditional operator. The reason that this operator exists in the C language is that it allows the compiler to produce code that is more optimized than if-then-else, and it is important to understand this usage.
3) Be careful to enclose the parameters in parentheses in the macro.
4) I also use this issue to start discussing the side effects of macros, such as: What happens when you write the following code?
least = MIN (*p++, b);
2. An infinite loop is often used in embedded systems, how do you write a dead loop in C?
This problem is solved with several solutions. My preferred solution is to:
while (1)
{
}
Some programmers prefer the following scenarios:
for (;;)
{
}
This implementation is embarrassing for me because the syntax doesn't exactly say what's going on. If a candidate gives this as a plan, I'll use this as an opportunity to explore the fundamentals of what they do. If their basic answer is: "I was taught to do this, but never thought of why." "It will leave a bad impression on me.
The third option is to use a goto
Loop:
...
Goto Loop;
If the candidate gives the above scenario, it means that either he is an assembly language programmer (which may be a good thing) or he is a Basic/fortran programmer who wants to enter a new field.
3.
A) An integer number (an integer)
b) A pointer to the integer number (a pointer to an integer)
c) A pointer to a pointer to a pointer that points to a number of integers (a pointer to a pointer to an intege) r
d) An array of 10 integers (an arrays of ten integers)
e) An array of 10 pointers that point to an integer number. (An array of ten pointers to integers)
f) A pointer to the array of 10 integer numbers (a pointer to an array of ten integers)
g) A pointer to the function that has an integer parameter and returns an integer number (a pointer to a function this takes an integer as an argument and returns an integer)
h) An array of 10 pointers that point to a function that has an integer parameter and returns an integer number (an array of ten pointers to functions that taking an integer argument and retur n an integer)
The answer is:
a) int A; An integer
b) int *a; A Pointer to an integer
c) int **a; A pointer to a pointer to an integer
d) int a[10]; An array of ten integers
e) int *a[10]; An array of ten pointers to integers
f) Int (*a) [10]; A pointer to an array of ten integers
g) Int (*a) (int); A pointer to a function A, takes an integer argument and returns an integer
h) int (*a[10]) (int); An array of ten pointers to functions A, a integer argument and return an integer
I agree that there are a number of questions that people often claim are the kind of questions that need to be answered by flipping a book. When I wrote this article, I did check the book in order to determine the correctness of the grammar. But when I was interviewed, I expected to be asked the question (or similar question). Because during the interview, I was sure I knew the answer to the question. If the candidate does not know all the answers (or at least most of the answers), then there is no preparation for the interview, and if the interviewer does not prepare for the interview, then why should he be prepared?
4.
What is the role of the keyword static?
Few people can answer this simple question completely. In the C language, the keyword static has three distinct effects:
1) in the function body, a variable declared as static maintains its value in the process of the function being called.
2) within the module (but outside the function body), a variable declared as static can be accessed by a function within the module, but not by other functions outside the module. It is a local global variable.
3) within the module, a function declared as static can only be called by other functions within this module. That is, this function is restricted to the local scope of the module that declares it.
Most candidates are able to answer the first part correctly, and part of them can answer the second part correctly, with very few people able to understand the third part. This is a serious drawback for a candidate because he clearly does not understand the benefits and importance of localizing data and code scope.
5. What is the meaning of the keyword const?
As soon as I heard the interviewee say "Const means constant", I knew I was dealing with an amateur. Last year Dan Saks has completely summed up all the usages of const in his article, so ESP (translator: Embedded Systems programming) Every reader should be very familiar with what const can and cannot do. If you've never read that article, you can just say that const means "read-only". Although this answer is not a complete answer, I accept it as a correct answer. (If you want to know more about the answer, read Saks's article carefully.) )
If the candidate can answer the question correctly, I will ask him an additional question:
What does the following statement mean?
const int A;
int const A;
const int *a;
int * const A;
int const * a const;
The first two functions are the same, a is a constant integer number. The third means that a is a pointer to a constant integer number (that is, the integer number is not modifiable, but the pointer can). The fourth meaning a is a constant pointer to an integer number (that is, the integer number pointed to by the pointer can be modified, but the pointer is non-modifiable). The last one means that a is a constant pointer to a constant number (that is, the integer number pointed to by the pointer is not modifiable and the pointer is not modifiable). If the candidate can answer these questions correctly, then he leaves a good impression on me. Incidentally, perhaps you may ask, even without the keyword const, it is easy to write the function of the correct program, then why do I value the keyword const? I also have the following several reasons:
1) The function of the keyword const is to convey very useful information to the person who is reading your code, and in fact, declaring a parameter as a constant is to tell the user the purpose of the application of this parameter. If you have spent a lot of time cleaning up the rubbish left by others, you will soon learn to thank for the extra information. (Of course, it's very rare for a const programmer to leave rubbish for others to clean up.) )
2) using the keyword const may produce more compact code by giving the optimizer some additional information.
3) The use of the keyword const makes it natural for the compiler to protect those parameters that you do not want to change, and to prevent them from being unintentionally modified. In short, this can reduce the occurrence of bugs.
6. What does the keyword volatile mean? and gives three different examples.
A variable that is defined as volatile means that the variable may be unexpectedly changed so that the compiler does not assume the value of the variable. Precisely, the optimizer must carefully re-read the value of the variable each time it uses the variable, rather than using the backup stored in the register. Here are a few examples of volatile variables:
1) Hardware registers for parallel devices (e.g., status registers)
2) non-automatic variables that are accessed in an interrupt service subroutine (non-automatic variables)
3) variables shared by several tasks in multi-threaded applications
The person who cannot answer the question will not be hired. I think this is the most basic problem of distinguishing between C programmers and embedded system programmers. Embedded guys often deal with hardware, interrupts, RTOs, and so on, all of which require volatile variables. The content that does not understand volatile will bring disaster.
Assuming that the interviewee has answered the question correctly (well, wondering if this is the case), I'll look at it a little bit and see if this guy is straight on about the importance of volatile.
1) can a parameter be either const or volatile? explain why.
2); Can a pointer be volatile? explain why.
3); What is wrong with the following function:
int square (volatile int *ptr)
{
return *ptr * *PTR;
}
Here's the answer:
1) Yes. An example is a read-only status register. It is volatile because it can be changed unexpectedly. It is const because the program should not attempt to modify it.
2); Yes. Although this is not very common. An example is when a service subroutine fixes a pointer that points to a buffer.
3) This piece of code is a bit perverted. The purpose of this code is to return the pointer *ptr to the square of the value, but since *ptr points to a volatile parameter, the compiler will produce code similar to the following:
int square (volatile int *ptr) {
int A, B;
A = *ptr;
b = *ptr;
return a * b;
}
Because the values of the *ptr can be unexpectedly changed, A and B may be different. As a result, this code may return to the square value you expect! The correct code is as follows:
Long Square (volatile int *ptr) {
int A;
A = *ptr;
Return a * A;
}
7. Bit operation (bit manipulation)
What is the output of the following code and why?
void foo (void)
{
unsigned int a = 6;
int b =-20;
(A+b > 6)? Puts ("> 6"): Puts ("<= 6");
}
This question tests whether you understand the principle of automatic conversion of integers in C, and I find that some developers know very little about these things. However, the answer to this unsigned integer question is that the output is ">6". The reason is that when there are signed and unsigned types in an expression, all operands are automatically converted to unsigned types. So 20 becomes a very large positive integer, so the expression evaluates to more than 6. This is important for embedded systems that should be used frequently for unsigned data types. If you answer the wrong question, you will not get to the edge of the job.
8. Typedef is frequently used in the C language to declare a synonym for a data type that already exists. You can also use a preprocessor to do something similar. For example, consider the following example:
#define DPS struct S *
typedef struct S * tPS;
The intent of both of these cases is to define DPS and TPS as a pointer to the struct S. Which method is better? (if any) why?
This is a very delicate question, and anyone who answers the question correctly (for the right reason) should be congratulated. The answer is: TypeDef is better. Consider the following example:
DPS P1,P2;
TPS P3,P4;
The first extension is a
struct S * p1, p2;
.
The code above defines P1 as a pointer to a struct, p2 as an actual structure, which may not be what you want. The second example correctly defines the P3 and P4 two pointers. The Obscure grammar
9. What data in C + + is allocated in the stack or heap, and is the new allocation data in the near or far heap?
A: Stack: Store local variables, function call parameters, function return value, function return address. Managed by the system
Heap: Application run-time dynamic request, new and malloc requested memory on the heap







C + + Knowledge Points series three


About preprocessing
#define的常量用const取代, macros are replaced with inline functions.
functions defined in the class definition are automatically inline functions. You can also use the inline modifier function to make it inline. Inline is only useful if the function is defined. Therefore, inline functions in the header file are functional bodies. The inline function is also an inner join.
A friend's function can also be inline.
Inline is only an optimization hint to the compiler, and the compiler does not necessarily inline all inline.

Non-replaceable preprocessing capabilities:
String (#, convert identifier to string): #define DEBUG (x) cout << #x "=" << x << Endl
Mark Paste (# #, connect two identifiers to form a new identifier): #define FIELD (a) char* a# #_string; int a# #_size

Static
The compiler guarantees that the built-in type of static is assigned an initial value. Calls its default constructor for a static object.
The destructor for the static object is called automatically when the main () function ends or when exit () is called. Therefore, calling exit () in the destructor of a static object may result in a recursive call. Calling abort () does not automatically call the static object's destructor.
The global object is static. Therefore, the construction and destructor of the global object can be used to do some work before entering main () and exiting main ().
For global objects, because they are stored statically, the effect of using the static modifier simply makes it an inner join.

Definition of a static data member:
Class A {
static int i;
Public
//...
};
int a::i = 1;
Only a static const integer can be initialized inside a class, and all other types must be initialized in the external (file domain). Therefore, a static member cannot be defined in a local class (a class defined in a function).

The static member function is defined in the class. Common to all objects of this class, you can use the class name directly when calling:: Function name.
The static member function can only access static members because the static member does not have this.
Static initialization dependency (preferably avoided). You can refer to the implementation of iostream (CIN, cout, and Cerr are static objects in different files) or another (incredibly nameless!). Method

Namespace
#include <iostream.h>
means the
#include <iostream>
using namespace Std;
Because namespaces do not exist before normalization, all content in. h is exposed
The namespace definition can only appear in the global domain or in another namespace. There is no semicolon after the {} definition. Can span multiple file definitions (not duplicate definitions). You can also define aliases. Such as:
namespace Bob = bobssuperduperlibrary;
Each compilation unit has an unnamed namespace. By putting variables into this namespace, you do not have to declare them as static (inner joins). This method is used in C + + to achieve static in the file.

The friends declared in the class will also enter the namespace that the class resides in.
The using namespace is only valid within the current domain (all names in the namespace are injected into the current domain). The names introduced in the using namespace can be overwritten.
Connection mode. For example, a function in a library called C is required in C + +:
extern "C" float f (int A, char b);
Otherwise, the join program may not be able to resolve the function call. Typically, the compiler will handle this situation automatically.


References and pointers
A reference must be initialized at creation time to reference a variable, and the referenced object cannot be changed once it is initialized.
When a function returns a reference, it is important to note that the referenced object cannot exist after the function returns, such as a variable inside a function.
The copy constructor accepts a reference to this class. Defining a copy constructor requires that you define the constructor function.
By declaring a private copy constructor, you can prevent the object from being passed value.

Pointers to members in a specific class:
Statement:
int ObjectClass::* pointertomember;
Initialization
int ObjectClass::* pointertomember = &ObjectClass::a;
Use:
Objectpointer->*pointertomember = 47;
Object.*pointertomember = 47;
Also applicable for member functions


Operator overloading
The overloaded operator must accept at least one custom type. Operators that accept parameters that are built-in types cannot be overloaded.
When an operator is overloaded as a member function of a class, the object of the class is used as the first argument. Notice how the function returns at this point.
The overloaded ++a calls operator++ (a), and the overloaded a++ invokes operator++ (A, int), where the second int parameter is not used, but is used to differentiate between prefix and suffix invocation. --the same is true of overloading.
= AND [] can only be overloaded as member functions. () can be overloaded only as a member function, with any number of arguments. (If you can not be overloaded as a member function, the operation of the built-in type can be overloaded, which makes no sense)
And->* can only be overloaded as member functions, but there are certain restrictions on the return value.
. and. * Cannot be overloaded

return Value optimization:
Integer tmp (LEFT.I + right.i);
return TMP;
It takes three steps for the compiler to complete (construct, copy, refactor), and
Return Integer (left.i + right.i);
It only takes one step

Overloaded when selected as a member or as a non-member function:
All unary operators are recommended as members
= () []->* must be a member
+= -= /= *= ^=
&= |=%= >>= <<= recommended as a member
All other two-dollar operators are recommended as non-members

When the object has not been created, = the constructor or copy constructor is called to initialize the object, and when the object is created, = is called the operator=. So
Fee Fee (1);
Fee Fum (FI);
This is better than
Fee Fee = 1;
Fee fum = fi;
This is a clear notation.

When overloading an assignment operator, it is a good practice to first check whether you are assigning a value to yourself.
When there is a pointer in the object, the copy constructor usually needs to be copied with the content pointed to by the pointer. When this content is large, the method of reference counting is usually used, and the content is copied only if the data needs to be modified and the number of references is greater than 1 o'clock. This technique is called copy-on-write.
When a constructor accepts an object of another type as a parameter, the compiler can use it for automatic type conversion. If you do not need such an automatic conversion, add explicit before the constructor.
You can also overload the operator type name to define an automatic type conversion. Since this type conversion is done by the source object (unlike the constructor's type conversion is done by the target object), you can complete the conversion of the custom object to the built-in type.
When operator overloading is a non-member function, automatic type conversions can be performed on both sides of the operator.
When providing automatic type conversions, note that there is only one conversion path between the two types, or a two semantic error occurs.


New and delete
New allocates space for the object and calls the constructor. Delete invokes the object's destructor and frees the object's space.
Delete is not valid for 0 pointers, so people usually set the pointer to zero after the delete to prevent problems caused by multiple deletes.

Delete void* may cause problems. Because the compiler does not know the specific type, it causes the object's space to be freed without calling the destructor. This may cause a memory leak.
A * p = new a[100]; Allocates space for each object in the array and invokes the constructor for initialization.
delete []p; do the opposite. After the delete [] indicates that the pointer is just the first address of the array, the compiler automatically gets the size of the array to complete the release work. Because it represents the first address, it is best to define a constant:
A * Const P = new A[100];
When new cannot find a space allocation, New-handler is called. Its default behavior is to throw an exception. You can define functions as New-handler by using Set_new_handler () in New.h.

operator new AND operator delete can be overloaded to accomplish some of the custom memory management functions:
void* operator new (size_t SZ)
void operator Delete (void* m)
When new and delete are overloaded as member functions of a class, these overloaded operators are called when space is allocated for objects of that class.
operator new[] and operator delete[] that are used to allocate space for an array can also be overloaded. The actual space occupied is 4 bytes more than allocated, and is used by the system to store the size of the array.

The overloaded new can accept any number of arguments, such as defining a second parameter, to indicate where to allocate space:
void* operator New (size_t, void* Loc)
When used:
x* XP = new (a) X;
A is a second parameter. Using this form of new may require an explicit call to the destructor:
Xp->x::~x ();
(because the object might not be built on the heap, use Delete to free up space on the heap)


Inherited
Both composition and inheritance need to initialize the child object in the constructed initialization list.
Once a function with the same name in the superclass is defined in the subclass, all functions of the same name in the superclass will become invisible, regardless of whether the function is of the same type.
constructors, destructors, operator= do not enter subclasses when inheriting.
Inheritance is private by default, that is, public members in a superclass also become private in subclasses. If you want to expose only certain members, you can use using in the public section of the subclass. In this case, overloaded functions with the same name will be completely exposed.


Polymorphic
The virtual keyword is used in C + + to declare that a function is delayed bound (or dynamically bound). Virtual is not required in the definition of a function. After using virtual, the upcast is called the overloaded function of the subclass, otherwise it can only call the base class. (c + + uses virtual to make dynamic binding optional, which is for efficiency reasons.) Other languages, such as Java and Python, are used dynamically bound by default)
Classes that have pure virtual functions are abstract classes (an interface is provided). The pure virtual function adds = 0 after the virtual definition.
Subclasses that inherit an abstract class must implement all pure virtual functions in the base class, or they are abstract classes.

A pure virtual function cannot be defined inline. After the definition, you can use the quilt class.
The upcast of the value will cut the object, that is, the subclass will be cut to only the part of the base class. Abstract base classes can avoid this situation because abstract classes do not allow instantiation.
Constructors cannot be virtual, and destructors can.


Template
Inheritance can reuse objects, and templates can reuse code.
You can use built-in types when defining a template. Their values can be constants. Such as:
Template<class T, int size = 100>
The template can be used not only to create class templates, but also to create function templates.


Miscellaneous
An array of characters with no punctuation between them is automatically concatenated
The C + + standard contains not STL, but the C + + standard library, which is evolved by STL.
A type conversion in C + + can be in the form of a function, such as float (n) equivalent to (float) n.
Display type conversions in C + + (provides an easy-to-discern form):
Static_cast: You can avoid compiler warnings when narrowing a type, and can also be used for type relaxation, void* casts, and auto-implicit conversions.
Const_cast: For converting const and volatile, such as pointing a normal pointer to a const
Reinterpret_cast: Treat one type as a different type
dynamic_cast: For downcast
sizeof is an operator instead of a function, which is used for types with parentheses, such as sizeof (double), used for variables, such as sizeof X.




C&c++--c and C + + knowledge points

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.