Thursday, July 11, 2013

Functions and Arrays



From my most recent reading I have learned two things: my comprehension of new material is varying while my comfort with terminology and syntax is steadily improving. Let me explain.
                The topics regarding C++ which I just covered are functions and arrays. Functions are not tricky beasts to tame, especially if one has spent a year in any algebra class. The purpose of a function is that it may be called within a program to carry out a series of statements, or code, without crowding the main function. In fact, right in that previous sentence you realize you have been working with a function since the very beginning: the main function. All functions behave as the main function, as in they are called to carry out a series of statements. They can be defined, given parameters, some statements, and boom: ready to go.
                However, as the tutorial section Functions (II) has demonstrated to me, I am losing my reign over functions. Their capabilities slip from my grasp in the presence of referencing, while tricks such as default values and overloading do not appear, at the outset, useful to me. With time in class and with assignments, I am sure such concepts will become illuminated. And inline functions were a bit over my head. I grasp the gist of saving processing, but the entry keeps the topic unclear.
                Yet, in terms of recursivity I am relatively at peace. The concept of having a function call itself in performing its statements seems somewhat similar to the purposes of loops. I am also reminded of a somewhat humorous Saturday Morning Breakfast Cereal (a comic). The final entry on declaring functions presented itself as not challenge, and it was reminiscent of my instructor’s words regarding the topic. It is tidy, useful, and overall good programming to declare a function and then define it after the main function. Doing such will create cleaner code. This habit, known as prototyping, is one that will take some adjustment (“I want to define now!”), but should be worth it in the end.
                I am glad to finally read about arrays, for I have always scratched my head a bit at their reference. In prior weeks, I picked up the concept of arrays (as in they can store a range of values). Yet I had never really understood their structure, or syntax, or how they could be implemented in a program. Now, I might say, with some certainty, that I partially comprehend a fair portion of array basics.
                For instance, I now know that creating an array, such as “int array[6]” will enable me to store six integers within said array, and these integers can be used after the array’s declaration in several ways. Say I created “int array[6] (1,2,3,4,5,6,)”, and then grew partial to “array[3]”, which holds the value of 4 (in arrays, the values begin with place 0).  I could then establish that a variable, say a, is equivalent to this value which I have declared in the array, as in “array[3] = a”. Well done, I say. Now, what utility does this contain?
                At the moment, I am not one to say. Given some class time, I am bound to learn just how useful the creation and usage of arrays can become. I am bound to discover how complicated they can be, as multidimensional arrays come into play. Still, I have become more at peace with the concepts behind them, and that is something (probably). 

Links:
http://www.cplusplus.com/doc/tutorial/functions2/
http://www.cplusplus.com/doc/tutorial/arrays/
http://www.smbc-comics.com/

No comments:

Post a Comment