C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
Expand Post »
In my old C++ programming classes I would often trip up on theses basic concepts when things got more and more complicated:
1. Arrays
2. Functions
3. Inheritance
4. Call by Reference
5. Call by Value
6. Pointers
I kind of know how they work but don't really know what they are good for in real life applications. Could somebody explain his or her:
(A) Definition of the concept
(B) Understanding of what the concept does/how it works
(B) Quick example of the concepts use in real life applications (i.e. what is it good for?)
I'll put my understandings and explanation up later tonight, tomorrow the latest
Re: C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
Quote originally posted by Narue ...
Each of these are rather broad topics. Can you cut it down to specific questions so we don't have to write page after page of tutorials?
Okay, lets deal with functions first, then inheritance
lets start with the format of a function:
return-value-type function name( parameter-list)
{
declaractions and statements
}
^^^what does all that mean, and what does it mean whem you have nothing in the parameter-list compared to when you do have something(s) in the parameter-list?
Re: C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
return-value-type Any value, or none at all, that you want to return from the function: an error code, a calculated result, etc.
parameter-list Any value(s) -- or possibly references in C++, or none at all, that you want to pass to the function: a pointer to an array to calculate the sum, for example.
declaractions and statements The "meat"; what it takes to do whatever it is the function does.
what does it mean whem you have nothing in the parameter-list compared to when you do have something(s) in the parameter-list?
It means whatever you want it to mean. This is a little like asking how a painter turns paints and canvas into a portrait.
hmmm...thanx for the break down...ok so did you pass parameters x and y in function multiply() to function multiply() found in the function main()? am i right or wrong?
and what is this "%d", what does it do?
please explain whats going on in the printf() function
Hmmmmm....in the function multiply() how did you go from parameters x and y to i and j, that looks like a "call-by-reference" but i don't understand why you did that and how it works, please explain dave
Re: C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
Quote originally posted by Fasola ...
hmmm...thanx for the break down...ok so did you pass parameters x and y in function multiply() to function multiply() found in the function main()? am i right or wrong?
In the first example, the values 2 and 3 from the call to multiply in main() become the values of the parameters x and y in the function multiply().
Quote originally posted by Fasola ...
and what is this "%d", what does it do?
please explain whats going on in the printf() function
It is just printing an integer, which was the result returned by the function.
Quote originally posted by Fasola ...
Hmmmmm....in the function multiply() how did you go from parameters x and y to i and j
In the second example, the values of i and j in main() are passed to the function multiply() as the parameters x and y.
Quote originally posted by Fasola ...
that looks like a "call-by-reference" but i don't understand why you did that and how it works, please explain dave
Nope. Pass by value. A copy of the value of i, for instance, is passed to the function as the parameter x.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.