From c8b2296bdd590c16e7c4948e6c56df9b93fab8b1 Mon Sep 17 00:00:00 2001 From: Captain ALM Date: Mon, 15 Aug 2022 12:48:53 +0100 Subject: [PATCH] Value of variables in expression order not guaranteed. --- main.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/main.cpp b/main.cpp index 6a42f28..359256d 100644 --- a/main.cpp +++ b/main.cpp @@ -1,13 +1,16 @@ #include +int getValue() +{ + std::cout << "Enter an integer: "; + + int x{}; + std::cin >> x; + return x; +} + int main() { - //char name[5] = {'t', 'e', 's', 't', '\0'}; - char name[5] = "test"; - char* t = name; - std::cout << t; - t[1] = 'a'; - t[4] = 'b'; - std::cout << t; - return 0; + std::cout << getValue() + (getValue() * getValue()); // a + (b * c) + return 0; }