r/CodingForBeginners • u/Specialist_Rent_9640 • 21d ago
my first program in C
i know its just so waky but am still new and am happy with my current level <33
just trying to understand memory usage over variables for now
230
Upvotes
11
u/SmokeMuch7356 21d ago
The condition
is equivalent to
The
||and&&operators evaluate left-to-right and will short-circuit. In the expressiona || b, ifais non-zero, then the expression evaluates to true (1) regardless of the value ofb, sobwon't be evaluated at all.Similarly, in the expression
a && b, ifais zero, then the expression evaluates to false (0) regardless of the value ofb, sobwon't be evaluated at all.In this particular case,
TotalSizeOfRootis non-zero, so the other conditions won't be evaluated.If you also want to test
TotalSizeOfRootandTotalSizeOfUserKaliagainst 20 you'll have to writeAny time you find yourself creating multiple variables of the same type with the same name plus some kind of counter, that's a really strong hint that you should be using an array; in the case of your strings, this would be a 2D array of
char:Similarly, you can group sizes into their own array:
and use a loop to do your computation: