Hey everyone! I'm a beginner at C programming and I've been studying quite a bit, but I often run into tricky problems during exams that I haven't encountered before. For example, I just learned that `printf` returns the number of characters printed, but that's not something I've seen in a question before. In my recent exam, it was used within a ternary operator: `c = (a > b) ? a = b : b = a;`. I didn't know that executing `b = a` would also update the value of `c`.
Also, I stumbled upon this piece of code: `int a = 1; if (a = 0)`. I realized that `a` would get assigned the value of `0` instead of being checked for equality, which was a bit confusing. Can anyone recommend resources where I can find more of these tricky C questions to practice on? I could really use some help!
2 Answers
The fact that `printf` returns the number of characters printed is something that's documented, but many don't usually use it in casual coding. You’re right that it's important for the ternary operator — assignments in C can have values, and that's a common source of errors, especially if you're not careful.
As for some tricky questions, I’d recommend checking out programming challenge websites like HackerRank or LeetCode. They often have questions that will test those tricky aspects of C and help you learn in the process!
These are basic concepts that should be covered in most C textbooks. For extensive learning, check out free online tutorials or great YouTube channels for programming beginners! My recommendation would be to look up tutorials on sites like Codecademy or freeCodeCamp. They can help clarify these tricky bits!
Could you tell me the name of the textbook you were referring to?

Can you suggest any website for practicing specifically? I'm looking for focused practice.