Make sure you understand that just because the program compiles without
error, there's absolutely no guarantee it will do what you intended.
That being said, it SHOULD do what you programmed.
The best way to work through some of these programs is to write or find
minimum code samples that do the thing you're trying to do and modify
or compare it.
That is one reason why every language typically has a "Hello, World!"
sample program. Start with the basics.