Hello Bart (and maybe Nik and Arbee!)
Do you remember I am learning C in my spare time? Well, I've just reminded you. Progress is steady, albeit slow (a problem with learning as a hobby!). I am still up against the problem of finding a nice warm and welcoming environment to bounce questions and problems around, however, I decided to take the plunge and potentially ask some stupid questions here.
Basically, I'm working my way through my textbooks which I acquired and I have gone through the first few chapters a few times to ensure I get my head around the concepts.
I do wonder however, how useful some of the information is. What I am getting at, is whether I am spending too much time on some concepts and to what extent my time would be better spent on other areas?
I wrote the following piece of code to explain the difference between prefix and postfix notation. I spent bloody ages on this chapter, but I am wondering to what extent this would be used in - for example - emulation and in C more generally? You may remember than emulation is my 'hook' so I tend to try and apply my learning to the concept. Some things I can see the relevance of, others less so. Also, although I understand the logic, there must be a better way of re-declaring the values, rather than simple repetition? Couldn't I just declare them at the beginning and refer the code back to the beginning in a loop with some form of if/or statement based on != to the original values? If so, what would be the most efficient way of writing the code?
Anyway, here is the code (sorry if it's a bit shabby!)
main()
{
int x = 2, y = 3, result; // initialise and declare the variables
/*Show values before and after expression*/
printf("\nSTARTING VALUES: x = %d; y = %d\n", x, y);
result = ++x + y;
printf("PREFIX: The result of ++x + y = %d\n", result);
printf("After calculation x = %d and y = %d\n", x, y);
x = 2, y = 3; /*Restore values*/
printf("\nSTARTING VALUES: x = %d; y = %d\n", x, y);
result = x++ +y;
printf("POSTFIX: The result of x++ +y = %d\n", result);
printf("After calculation, x = %d and y = %d\n", x, y);
}
Any help or encouragement is very much appreciated. I am still really enjoying it, but there's so much to learn and although I honestly don't want to cut corners, I do want to ensure I am learning the appropriate things effectively, so if I could bend your ear about real-world (doesn't have to be emulation-centric) examples of where pre and post notations are needed, then so much the better.
Thanks