summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-08-19 15:22:32 +0200
committerOskar <[email protected]>2024-08-19 15:22:32 +0200
commitd0c6ac2b68380020d76d7f938307e056a25eb5f5 (patch)
tree09537a1676d9e9d5834b92de74076001e90465bf
parent19903ae3536255dfa2778846275267605cee9f7e (diff)
confusing exercise, not really sure what a correct answer would be to this
-rw-r--r--4p19.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/4p19.cpp b/4p19.cpp
index ab94f28..86edd19 100644
--- a/4p19.cpp
+++ b/4p19.cpp
@@ -14,6 +14,29 @@ int main () {
int aa = 12374;
int ival = 0;
ptr = &aa;
- vector<int> vec;
+ std::vector<int> vec = {1,2,3,4,5,6,7,8};
+
+ if(ptr != 0 && *ptr++) {
+ // Seems fine
+ // I think it's a bit difficult because we sort of have to
+ // assume what the author wants to actually do. Which is why
+ // it is a little unclear how safe any of this really is.
+ // The expression itself seems to be fine. But were we
+ // to dereference it inside this if statement then things
+ // could surely go very wrong. But then again,
+ // i have no idea what the author intended to check for with the expression
+ // I could say the same about the other 2 expressions in this program.
+ }
+
+ if(ival++ && ival) {
+ // Seems fine
+ }
+
+
+ if(vec[ival] <= vec[ival + 1]) {
+ ++ival;
+ // Undefined: vec[ival++] <= vec[ival]
+ }
+
return 0;
}