| | |
C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2005
Posts: 188
Reputation:
Solved Threads: 0
C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
0
#1 Mar 9th, 2005
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
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
0
#2 Mar 9th, 2005
•
•
Join Date: Jan 2005
Posts: 188
Reputation:
Solved Threads: 0
Re: C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
0
#3 Mar 9th, 2005
•
•
•
•
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?
that one always gets me
Re: C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
0
#4 Mar 9th, 2005
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.
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.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Jan 2005
Posts: 188
Reputation:
Solved Threads: 0
Re: C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
0
#5 Mar 9th, 2005
Re: C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
0
#6 Mar 9th, 2005
C++ Syntax (Toggle Plain Text)
#include <stdio.h> int multiply(int x, int y) { return x * y; } int main() { int result = multiply(2,3); printf("result = %d\n", result); return 0; } /* my output result = 6 */
C++ Syntax (Toggle Plain Text)
#include <stdio.h> int multiply(int x, int y) { return x * y; } int main() { int i, j; for (i = 1; i < 10; ++i) { for (j = 1; j < 10; ++j) { printf("%2d ", multiply(i, j)); } putchar('\n'); } return 0; } /* my output 1 2 3 4 5 6 7 8 9 2 4 6 8 10 12 14 16 18 3 6 9 12 15 18 21 24 27 4 8 12 16 20 24 28 32 36 5 10 15 20 25 30 35 40 45 6 12 18 24 30 36 42 48 54 7 14 21 28 35 42 49 56 63 8 16 24 32 40 48 56 64 72 9 18 27 36 45 54 63 72 81 */
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Jan 2005
Posts: 188
Reputation:
Solved Threads: 0
Re: C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
0
#7 Mar 10th, 2005
•
•
•
•
Originally Posted by Dave Sinkula
C++ Syntax (Toggle Plain Text)
#include <stdio.h> int multiply(int x, int y) { return x * y; } int main() { int result = multiply(2,3); printf("result = %d\n", result); return 0; } /* my output result = 6 */
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
•
•
•
•
Originally Posted by Dave Sinkula
C++ Syntax (Toggle Plain Text)
#include <stdio.h> int multiply(int x, int y) { return x * y; } int main() { int i, j; for (i = 1; i < 10; ++i) { for (j = 1; j < 10; ++j) { printf("%2d ", multiply(i, j)); } putchar('\n'); } return 0; } /* my output 1 2 3 4 5 6 7 8 9 2 4 6 8 10 12 14 16 18 3 6 9 12 15 18 21 24 27 4 8 12 16 20 24 28 32 36 5 10 15 20 25 30 35 40 45 6 12 18 24 30 36 42 48 54 7 14 21 28 35 42 49 56 63 8 16 24 32 40 48 56 64 72 9 18 27 36 45 54 63 72 81 */
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
and what does the function putchar() mean
Re: C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
0
#8 Mar 10th, 2005
•
•
•
•
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?
•
•
•
•
Originally Posted by Fasola
and what is this "%d", what does it do?
please explain whats going on in the printf() function
•
•
•
•
Originally Posted by Fasola
Hmmmmm....in the function multiply() how did you go from parameters x and y to i and j
•
•
•
•
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
•
•
•
•
Originally Posted by Fasola
and what does the function putchar() mean
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Jan 2005
Posts: 188
Reputation:
Solved Threads: 0
Re: C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
0
#9 Mar 10th, 2005
•
•
•
•
Originally Posted by Dave Sinkula
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().
In the second example, the values of i and j in main() are passed to the function multiply() as the parameters x and y.
i noticed how you said "become the value"
let me make sure i got that right
does the funtion
multiply(int x, int y)
CALL THE VALUES 2 and 3 (i.e. call-by-value")
of the function
multiply(2,3);
to perform
return x * y;
i'm not sure, is that what you meant by "become"?
•
•
Join Date: Jan 2005
Posts: 188
Reputation:
Solved Threads: 0
Re: C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
0
#10 Mar 10th, 2005
![]() |
Other Threads in the C++ Forum
- Previous Thread: Exercise using: unsigned int datecode(int year, int month, int day);
- Next Thread: Break Out Of A Function~
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






