Hi Thom, So you're saying, then, that main has to be at the bottom of the program?
Thomas Ward wrote:
Hi Dark, Smile. Welcome to the wonderful world of resource management. Don't feel too bad as this is an issue that comes up all the time with new programmers, because they often think as you do that a number is just a number and don't understand the difference between int, float, long, short, double, etc. Thing is with computers before you can actually store a value, like a number, you have to allocate enough memory on the heap to store it in memory. The value 3 requires a lot less memory than the value 3.14159265. For a small integer value like 3 you can use a short integer which will create just enough space in memory to handle that value. For a large floating point value like 3.14159265 you'll want a double value which will create a much larger block of memory on the heap for storage. While you could create all your numeric variables as double you'll run into the problem of waisting memory needlessly and waisting valuable system resources that could be used elsewhere. That is why it is a good idea only to asign enough space on the heap that you actually need rather than using the largest amount of memory possible just to store a small integer like 3. As for your script questions remember in the main() function when you call the add_numbers() function it hasn't been defined in your script yet. So while the add_numbers() function does indeed add two numbers but if you don't actually create that function somewhere in your script that function doesn't exist. As it happens you create the add_numbers() function after the main() function and it gets called by main to add two numbers of type int. Does that make sense? As far as the variables first and second you declared them as function parameters in the declaration of your function like int add-numbers (int first, int second) which is perfectly legal and proper code. What this does is tell the function that it requires two parameters of type int, and they must be entered when the function is called like int result = add_numbers (5, 7); in order to perform the calculation. Otherwise without declaring first and second as part of the function declaration you couldn't pass any values or parameters to the function. HTH On 3/24/10, dark <[email protected]> wrote:Hi. Having already read through the tutorial once, I stil find myself mildly confused on a couple of matters. Firstly, all the stuff relating to doubled short or long intagers and bits and bytes. I'm rather uncertain why or when I would want to use variables such as int8, double, or short which relate to the size of bits and bytes. Shorely, a number is a number and can be written as such? Secondly, I'm uncertain as to the difference betwene void functions and return result functions, and I must confess I don't follow this example: void main() { int x=add_numbers(3, 5); alert("Wow", "3 + 5 is... " + x + "!"); } int add_numbers(int first, int second) { int result=first+second; I can see that the alert will write the text string with the int x, however, hasn't the (3 + 5), already produced the result of 8 for x? Also, I have absolutely no idea what the business involving "int first" and "int second" is all about, sinse how does bgt know what first and second actually mean? it seems this function is working with a lot of intagers which haven't been defigned successfully, but which work (I tried creating a secript with this and it printed fine). Any thoughts on this would be appreciated.--- Gamers mailing list __ [email protected] If you want to leave the list, send E-mail to [email protected]. You can make changes or update your subscription via the web, at http://audyssey.org/mailman/listinfo/gamers_audyssey.org. All messages are archived and can be searched and read at http://www.mail-archive.com/[email protected]. If you have any questions or concerns regarding the management of the list, please send E-mail to [email protected].
--- Gamers mailing list __ [email protected] If you want to leave the list, send E-mail to [email protected]. You can make changes or update your subscription via the web, at http://audyssey.org/mailman/listinfo/gamers_audyssey.org. All messages are archived and can be searched and read at http://www.mail-archive.com/[email protected]. If you have any questions or concerns regarding the management of the list, please send E-mail to [email protected].
