commit 48df82e88e9fd09eb699bdc0c75a1cc9cb512745 parent 7847c7056abf9d1e2e88ef7c3e10f2889d869868 Author: Christos Margiolis <christos@margiolis.net> Date: Tue, 3 Mar 2020 20:37:59 +0200 updated 2.1 Diffstat:
M | assignment-2.1-fromctocpp/assignment-2.1-fromctocpp.cpp | | | 9 | +++++++++ |
1 file changed, 9 insertions(+), 0 deletions(-)
diff --git a/assignment-2.1-fromctocpp/assignment-2.1-fromctocpp.cpp b/assignment-2.1-fromctocpp/assignment-2.1-fromctocpp.cpp @@ -22,8 +22,17 @@ std::string defaultargs(std::string = "No"); int main(int argc, char **argv) { // Ερώτημα 1 + + // Τρόπος 1 const int x = 10; + std::cout << "First way" << std::endl; std::cout << "Old const value: " << x << std::endl << "New const value: " << modconst((int *)&x, 15) << std::endl << std::endl; + + // Τρόπος 2 + int *p = (int *)&x; + *p = 35; + std::cout << "Second way" << std::endl; + std::cout << "Old const value: " << x << std::endl << "New const value: " << *p << std::endl << std::endl; // Ερώτημα 2 Human *human = new Human("Christos");