1stAssign

 avatar
unknown
c_cpp
a month ago
2.7 kB
3
Indexable
#include <iostream>

int main() {
        int n = 1, p = 2, q = 3;

            // Expression 1: n <= p + q && n = p - q || n == 0
                bool result1 = (n <= p + q) && (n = p - q) || (n == 0);
                    std::cout << "Result of Expression 1: " << result1 << std::endl;
                        std::cout << "Explanation: Logical operators (&&, ||) are evaluated after comparison (<=) and assignment (=)." << std::endl;

                            // Reset values for the next expression
                                n = 1; p = 2; q = 3;

                                    // Expression 2: ++n + q-- / ++p - q
                                        int result2 = ++n + q-- / ++p - q;
                                            std::cout << "Result of Expression 2: " << result2 << std::endl;
                                                std::cout << "Explanation: Pre-increment (++), post-decrement (--), and division (/) are evaluated based on precedence." << std::endl;

                                                    // Reset values for the next expression
                                                        n = 1; p = 2; q = 3;

                                                            // Expression 3: n | p & q ^ p < q ? q : q
                                                                int result3 = n | p & q ^ p < q ? q : q;
                                                                    std::cout << "Result of Expression 3: " << result3 << std::endl;
                                                                        std::cout << "Explanation: Bitwise AND (&), OR (|), and XOR (^) are applied, followed by the ternary operator (? :)." << std::endl;

                                                                            // Reset values for the next expression
                                                                                n = 1; p = 2; q = 3;

                                                                                    // Expression 4: n < p ? n < p ? q * n + 2 : q / n + 1 : q - n
                                                                                        int result4 = n < p ? (n < p ? q * n + 2 : q / n + 1) : q - n;
                                                                                            std::cout << "Result of Expression 4: " << result4 << std::endl;
                                                                                                std::cout << "Explanation: The nested ternary condition (? :) is evaluated based on comparisons and arithmetic." << std::endl;

                                                                                                    return 0;
}
}
Editor is loading...
Leave a Comment