What's the difference between there two pointer statements [closed] - c++

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Just wondering what the difference was between these two lines of code and exactly what they are doing:
p*++
++*p

*p is value of the pointer pointing to.
also * uses as multiplication operator (int a = 5*6;)
p++ is post increment the value of p
++p is pre increment the value of p.
so
++*p is pre increment the value of pointer point to.
p*++ gives you a compile error, because of no meaning

Related

why addition using += operator is fast as compared to normal addition [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
str=str+(char)(newno+'0')
str+=newno+'0'
statement(1) is showing TLE whereas statement(2) does not.
The two statements are not at all identical. The first statement creates a new temporary string with newno+'0' appended, copies back the new string to str, and destroys the temporary object. The second can operate in place, if there is room in str.

Is it correct to fill sets contained in vector? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a vector<set<int>> v(10);. Each set can be filled by some data. Then I insert integers to randomly sets, e.g. v[5].insert(99);. Can it cause undefined behavior?
Only if you go out of bounds of the vector.
If your vector has at least 6 elements, then v[5].insert(99); is well defined.
To be sure that you don't, you can use the at accessor function:
v.at(5).insert(99);
Which will throw a std::out_of_range exception if you try to access past the end of the array.

no matching function for call to std::vector<int>::erase(int&) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a problem with this snippet of code:
for(int i=n;i>0;i--)
for(int j=0;j<i;j++)
if(docel[j]==docel[i])
docel.erase(j);
Why is that that my program doesn't compile? I also tried:
docel.erase(docel.at(j))
erase takes an iterator, not an index value. A simple fix is to use docel.erase(docel.begin() + j);
But your code looks buggy on two counts:
Take care not to increment j if you erase the (j)th element though: you'll skip over values.
You'll also need to adjust n if the number of elements in docel is reduced.

discussion about the scenarios that the insertion function of an STL vector may not work [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
it is strange that when I debugging a piece of code
a.insert(a.begin(), calculateSomeValue()); // a is of type std::vector<double>
this does not work because the value returned from the function calculateSomeValue is not inserted into a and the size of a does not increase.
but when I split it into two lines as the following, it works as I expect
double value = calculateSomeValue();
a.insert(a.begin(), value);
Do you happen to know what could be the possible reasons?
this is in windows
I can only assume that a side effect of calculateSomeValue() is changing a which invalidates all iterators.
Since the order of evaluation of arguments in a.insert(a.begin(), calculateSomeValue()); is unspecified it could be that a.begin() is evaluated before calculateSomeValue() invalidates all iterators to a. Which is undefined behaviour.

std::min is not returning the smaller of two values [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have this line of code:
out = std::min(x - 1, y - 1);
But it is returning the larger of the two quantities. How can this be?
This can only happen if x and y are unsigned types and one of them is zero.
Subtracting 1 from an unsigned value 0 will cause an unsigned value to wrap around to the largest possible value for that type. Hence the other value will be smaller.
As a side note: only blame your compiler / STL as a very last resort.