0

When I tried to return newGRect instead of rect in this case and compiled my whole program, I got the message of Segmentation fault. May I know why? Also, may someone tell me where to find a comprehensive note on 'return'?

//adapted from http://cs50.stackexchange.com/questions/1339/how-to-return-a-grect-from-initpaddle/1341?noredirect=1#comment12162_1341
// create a new GRect
GRect rect = newGRect(x, y, width, height); 
// do something to rect
return rect;
1

I would suggest that you visit the CS50 Study page for Functions to get a good basic understanding of how functions work, what it means to return etc. There are several slides, examples, and videos to help you.

Essentially, in your example, you are create a new GRect called 'rect' and then returning that object ('rect') to the calling function (which in this case will be main). In main you probably have something like

GRect paddle = initPaddle(window);

and then, your initPaddle function will include those lines you have pasted in your question.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .