// Basic demonstration of nested for loops.
#include <stdio.h>
int main(int argc, char* argv[])
{
// Outer loop will run until i equals 3
// (three times if starting at 0)
for (int i=0; i<3; ++i)
{
printf("\ti = %d\n", i);
// Nested loop will until j equals 6
// (three times if starting at 9)
for (int j=9; j>6; --j)
printf("\t\tj = %d\n", j);
}
return 0;
}
==150== Memcheck, a memory error detector
==150== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward
et al.
==150== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==150== Command: ./nested
==150==
i = 0
j = 9
j = 8
j = 7
i = 1
j = 9
j = 8
j = 7
i = 2
j = 9
j = 8
j = 7
==150==
==150== HEAP SUMMARY:
==150== in use at exit: 0 bytes in 0 blocks
==150== total heap usage: 1 allocs, 1 frees, 1,024 bytes allocated
==150==
==150== All heap blocks were freed -- no leaks are possible
==150==
==150== For lists of detected and suppressed errors, rerun with:
-s
==150== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
My solution to Exercise 3-2 from Part 1, Chapter 3 of C++ Crash Course. Github: https://github.com/pereiradaniel/CPP_CRASH_COURSE/blob/master/P1C3/EXERCISES/3_2.cpp Youtube: C++ Crash Course: Solution to Exercise 3-2.
For the last while, I have been busy with ESP32 and Arduino programming, but now I finally have time to ram through this book and the exercises. There are a few repositories on Github where people have offered solutions to some of these exercises, but I find that they are often not complete. Therefore, I am endeavouring to make a more complete listing, or at least fill in some of the holes. Here is a video and a link to the repository for the solutions to Part 1, Chapter 1. The exercises can be found at the end of each chapter. I am back-tracking a bit from where I am in Part 1 Chapter 5, which is where I am currently studying. Github: https://github.com/pereiradaniel/CPP_CRASH_COURSE/tree/master/P1C1/EXERCISES Video: C++ Crash Course: Solutions to Exercises in Part 1, Chapter 1.
My solution to Exercise 3-4 from Part 1, Chapter 3 of C++ Crash Course. This one was fairly straightforward, but it illustrates a very important thing on line 13. When you assign new_value to the reference original_ref , it assigns the value to the int that original_ref is pointing to. The result is that new_value and original both have the same value, 200. Github: https://github.com/pereiradaniel/CPP_CRASH_COURSE/blob/master/P1C3/EXERCISES/3_4.cpp Youtube: C++ Crash Course: Solution to Exercise 3-4.