•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 401,669 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,605 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 33199 | Replies: 45
![]() |
•
•
Join Date: Jan 2005
Posts: 188
Reputation:
Rep Power: 4
Solved Threads: 0
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
#2
Mar 9th, 2005
•
•
Join Date: Jan 2005
Posts: 188
Reputation:
Rep Power: 4
Solved Threads: 0
Re: C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
#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
#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.
•
•
Join Date: Jan 2005
Posts: 188
Reputation:
Rep Power: 4
Solved Threads: 0
Re: C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
#5
Mar 9th, 2005
Re: C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
#6
Mar 9th, 2005
#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
*/#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
*/•
•
Join Date: Jan 2005
Posts: 188
Reputation:
Rep Power: 4
Solved Threads: 0
Re: C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
#7
Mar 10th, 2005
•
•
•
•
Originally Posted by Dave Sinkula
#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
#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
#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
•
•
Join Date: Jan 2005
Posts: 188
Reputation:
Rep Power: 4
Solved Threads: 0
Re: C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
#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:
Rep Power: 4
Solved Threads: 0
Re: C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays
#10
Mar 10th, 2005
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
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~



Linear Mode