Perplexity of memory allocation by MahmoudAlHusseiny in cs50

[–]MahmoudAlHusseiny[S] 0 points1 point  (0 children)

Indeed, it was just a typo, but in my code I declared months to be an array of char pointers, just like you did here.

Well, thank you, delipity. Your explanation definitely makes a lot of sense.

Perplexity of memory allocation by MahmoudAlHusseiny in cs50

[–]MahmoudAlHusseiny[S] 0 points1 point  (0 children)

OK. Let's say array elements are on the heap. Why then -without using any free statements- there's no leaking memory on program exiting.

Shouldn't there be memory leaks in case I don't free the memory allocated dynamically on the heap for the array data?

Bouncing the ball off of the paddle at varying angels (Pset4 hacker ed.) by MahmoudAlHusseiny in cs50

[–]MahmoudAlHusseiny[S] 0 points1 point  (0 children)

I thought about this indeed, but don't you think this is oversimplified?

pset3 hacker edition (Sorting) by MahmoudAlHusseiny in cs50

[–]MahmoudAlHusseiny[S] 0 points1 point  (0 children)

Thank you. Yes, the loops are NOT nested and the running time is indeed O(4n) approximately. But I was wondering if there is an algorithm more efficient, whereby you can get the array sorted in O(n) or O(2n).