milon

joined 2 years ago
[–] [email protected] 1 points 2 months ago (3 children)

I did come across that link but didn't quite understand it. If looking only at 25 | 10, does the code not run as expected because 25 is 5 digits long and 10 is 4 digits long? Is that what's meant by "two equivalent length bit designs"?

Also, I can't tell if 10 | 4 = 7 or 10 | 4 = 14.

[–] [email protected] 1 points 1 year ago (1 children)

Yes, that helps. Thanks. I see now how n goes from 1 to 2 to 3...etc. Now not so sure how i = 1 when the for loop starts.

[–] [email protected] 2 points 1 year ago (1 children)

Yes - I finally caught that part about n as it's just moving in reverse so it gets decremented. Now I'm not sure about i. In the debugger when the program gets to the for loop both n and i are equal to 1. The n I understand but i?

[–] [email protected] 1 points 1 year ago

Gotcha. Thanks for the explanation.

[–] [email protected] 1 points 1 year ago (3 children)

I see. I guess my understanding was that the recursion was over after the recursive call, but it's actually for all the code in draw().

[–] [email protected] 1 points 1 year ago (1 children)

Thanks. I did see that. I have a general understanding of how recursion works I think where the function calls itself again and again but I don't get why the code (for loop) below the draw(n - 1) is recursive.

[–] [email protected] 1 points 1 year ago (5 children)

Right. I was aware it was recursion as stated in the title of my post. I had two questions specific to where the for loop returns after printing #.

[–] [email protected] 2 points 1 year ago (5 children)

Why does the for loop return when it hits the end of the function? Isn't the recursive portion already completed in draw(n - 1)? The rest of it is just normal non-recursive code if I understand it correctly.

[–] [email protected] 1 points 1 year ago (3 children)
[–] [email protected] 2 points 1 year ago (5 children)

It's supposed to be a pyramid but not my code. It's an example of a recursive function from a CS50 lecture and I'm just trying to understand how the code works line by line.

[–] [email protected] 2 points 2 years ago
[–] [email protected] 4 points 2 years ago* (last edited 2 years ago)

Ah ha! Yes, I did check the docs but I think I just glanced over that portion. Be more careful next time. Now that I took another look at the other ctype.h functions, they all return 1 or 0. I think I confused equivalent python built-in functions as those evaluated to true/false. The < is a less than sign but it seems it doesn't render correctly on Lemmy.

view more: ‹ prev next ›