-
Whether there will be an error report here is related to whether the address pointed to by p can be accessed.
In general, if the space pointed to by P is released and reused directly without overflowing, it is likely that there will be no error. The data you access is the data you have left.
However, if the space pointed to by p is reassigned to another program, it is likely to go wrong. Especially when you no longer have read permissions in the space, the system will definitely report an error.
You should have the experience of defining an array of characters: char a[10] = ;
When you access a[0] through a[9], it is both practical and logically normal. But you visit a[10], a[11], a[12]., it is also accessible, and there is a numerical output, as for where the error will be reported, depending on which address space you do not have read access.
So if you output a as %s, you're likely to see'a'There's a whole bunch of jumbled characters in the back.
-
The compiler just checks for syntax errors. Runtime errors are not possible.
After you release the memory that the p pointer points to, remember that p = null;
Otherwise, when you access the memory pointed to by the p pointer, an error will be reported.
-
I tried it here and my output was garbled. I think so. After using free, the memory pointed to by p has been released, but p still points to this memory, during the program run, that memory may have been occupied by other programs on the computer, or it may not be occupied, therefore, the output result is unknown, and the output world may or may output garbled characters.
-
1. It's convenient! (The benefits are not very obvious).
The dynamic allocation of language is simply the allocation of a piece of memory. C++'s new calls the constructor directly; Mainly reflected in non-basic data types! new type[n]; type **a; a = new *type[n];Then the for loop assigns new type[m] to each *a;
funciton(type& a);The advantage is that the value is passed relative to the pointer, and the value is passed directly. The pointer increases the difficulty of reading the program and is not easy to understand! Direct value transfer causes the reconfiguration of the object, which is equivalent to a copy of the original object, wasting storage space and operational efficiency!
4.Inline functions can realize runtime detection, but macros cannot, and inline uses the advantages of macros to improve the efficiency of the program! And it can be debugged. As long as they don't contain complex idioms, statements can be declared as inline functions!
A defined constant is the original statement replacement when used, while const is a defined variable that has its own memory space!
-
(1) It can be connected in series, which is easy to read; Type adaptation is less error-prone.
2) there is no need to calculate the size of the allocation; No type conversion is required, so it's less error-prone;
int *p = new int[n]; int (*p2) [m] = new int[n][m];m is constant;
int **pnm=new int* [n]; for(int row=0;row(3)string s="abc";string & myinit(string& sinit) When passing parameters for non-simple types of data or classes, you can avoid copying, and operate on the same class instance, which is more concise and secure than pointer reading.
4) inline can reduce the overhead of calling subroutines and parameter passing, and static functions cannot be declared as inline functions;
5) define defines the macro, which is copied at the point of use during compilation, which is essentially the reuse of C++**, and its value has been determined before compilation, and cannot be changed at runtime; const is defined as a variable with a constant property, the value of which is initialized and assigned at execution time, and can be forced to change by the program at runtime.
-
I took a closer look, what about your special exams or interviews, how good it is to study honestly, these characteristics are all language characteristics, don't you think it's stupid to compare who is good and who is bad? Is there a good thing about streaming? new and delete have no drawbacks?
Don't know how to apply for dynamic arrays? I'm really angry... Citations are even inferior to pointers in some places, and too many references in a large project can cause endless annoyance to the reader. Inline functions will be a big burden on the compiler, and bugs are not easy to find.
Const is better than Define, but Const cannot replace Define, Const can implement some of the functions of Define, C++ does not surpass C, nor can it replace C.
-
I'm here to make soy sauce.,I'm here.。。。
-
You can go to the Dinke Network for free consultation.
-
1a 2. x !=0 3.Constant 4Variables, arrays, pointers, references, vectors, pointers, pointers, don't know where to point and their values are random!
int fun( int & str int n )int temp = str[0] ;
for(int i = 1 ; i < n ; i++if( str[i] >temp )
temp = str[i] ;
return temp;
-
An integer expression.
5 ||x < 5
3.Pointer constants.
4.Arrays, strings.
5.A null pointer is a pointer that does not point to any memory unit, i.e. null is generally defined as (void*)0 or 0, and exists for comparison with various different types of pointers. Referencing a null pointer indirectly has the potential to cause memory read errors.
6.Please give a more detailed explanation.
There is no baggage, no pressure, so it is called aristocracy, so it is single, no baggage, no pressure.
In the process of growth and development, children are indispensable to the company of their parents, and only children who grow up in the company of their parents can cultivate a healthy personality. Therefore, in the process of growing up, no matter how busy the parents are, they must often find time to accompany their children and accompany them to grow up. But there is also skill in accompanying children, not simply sitting next to children, but high-quality companionship. >>>More
Put down your phone and spend time with your child. >>>More
Although everyone wants to find the best partner, which is the so-called high-quality partner, I think that finding a partner is not necessarily to find the best, but to find the most suitable for yourself, and the most suitable for yourself is the best, but it must be the best for you, not necessarily for others. >>>More
Lexiu**software,This should be the most usable **software on Android phones,This software,For multi-segment cutting、Fast cutting、GIF production、**compression,**Conversion has a very fast operation,In fact, the most commonly used personal is**,Through this software, you can synthesize**,Editing,Soundtrack,Dubbing,Texture,Fast shot、Slow motion、Reversing and other functions。