c++ Programming Tutorial 5
25 Responses to “c++ Programming Tutorial 5”Leave a ReplyPosted on July 27th, 2007 by admin Filed under C | |
|
c++ Programming Tutorial 5
25 Responses to “c++ Programming Tutorial 5”Leave a ReplyPosted on July 27th, 2007 by admin Filed under C | |
|
December 27th, 2007 at 7:27 pm
I just want to …
I just want to point out this code is rout with poor practices. One of these being hungarian notation. Make sure you do NOT use hungarian notation, it is a sign of very poor programming. If there is any confusion about what types your variables are or if the function you’re working on is nested so deeply and is multiple screens long, it is coded incorrectly and needs to be re-done. Never should such a hackish notation be adopted to fix the problem.
December 28th, 2007 at 10:18 pm
stfu noob.
stfu noob.
January 2nd, 2008 at 4:58 am
lol k
lol k
January 2nd, 2008 at 5:08 am
coz ur a noob lol!!!
coz ur a noob lol!!!
January 2nd, 2008 at 7:23 am
you are right. i do …
you are right. i do not understand why ppl are still using stupid hungarian notation although stuff developed so much not need HN to organize shits..:/
January 2nd, 2008 at 7:24 am
this dude is keep …
this dude is keep talking in the video but saying nothing useful…he is confused for himself. can anyone tell this dude stfu?
January 3rd, 2008 at 1:30 pm
i dont really think …
i dont really think theres a better, just maybe easier to use. im using Borland C++ 5.5.1 (which uses command prompt for compiling and editing) and i can follow these fine.
January 7th, 2008 at 8:36 pm
Shaddup!
Shaddup!
January 7th, 2008 at 8:37 pm
Cool…much better …
when’s the next one??
Cool…much better now
January 8th, 2008 at 7:13 am
i think that …
i think that bookgekgom have right, if u want to learn programming this noob ain’t gonna help ya’
January 10th, 2008 at 9:07 am
Al of your …
Thx, but I dont still know the pointers so good 
Al of your tutorials are great noobs like me
January 17th, 2008 at 9:56 pm
int main()
{
int* …
int main()
{
int* firstpointer = NULL;
int* secondpointer = NULL;
pointerfunction(a, b);
return 0;
You should really teach proper use of pointers; check if the pointers are valid. If they’re not, then return early.
}
January 23rd, 2008 at 5:37 pm
If you don’t define …
If you don’t define pointers, then you can get a value of anything, even the value of a string in a word document, and changing it.
January 29th, 2008 at 2:19 pm
I was wondering , …
I was wondering , im still not to sure about why to use pointers. ( Sorry im a PHP programmer so i havn’t really understood pointers:P )
But isnt it just the same to use:
pointerfunction(int var1, int var2){
cin >> var1 >> var2;
}
and ofc call it without all those pointers ?
Sorry for my noobness
January 30th, 2008 at 7:29 pm
So, i still don’t …
So, i still don’t see why someone uses pointers. I kinda get how to use them. How does using pointers do anything for you in this example.
January 31st, 2008 at 10:13 am
He was nice to …
He was nice to listen to and explained a lot of stuff in clear English, but it was kind of frustrating to write 5 lines of code only to hear “Whoops!” and then have to delete it.
Also, where is this huge tutorial #4 was “preparing” us for? I’m kinda dissapointed :\.
Oh well, pretty good tutorials :P.
February 2nd, 2008 at 8:53 am
i see that truth is …
i see that truth is hurting some people :>
February 3rd, 2008 at 11:51 pm
In this video, you …
In this video, you need pointers because you want the “called” function to be able to modify the variables that actually belong to the “caller” function.
There are two ways of passing a parameter to a function. By-value and by-reference.
February 3rd, 2008 at 11:54 pm
For example:
void …
For example:
void f1(int f1_x, int f1_y); // By-value
{
f1_x = 100; // Change only local variable, no effect on caller’s variable
f2_y = 200;
}
void f2(int* f2_x, int* f2_Y); // By-reference
{
*f1_x = 100; // Change the caller’s variable
*f2_y = 200;
}
February 3rd, 2008 at 11:55 pm
int main(void)
{
…
int main(void)
{
int main_x = 4;
int main_y = 5;
// You can call f1 like this
f1(main_x, main_y);
// OR like this
f1(4, 5);
// You have to call f2 like this
f2(&main_x, &main_y);
}
When a parameter is passed to a function, the called function makes a copy of that parameter and stores it in another local variable. In the above example f1 stores 4 in f1_x and 5 in f1_y as soon as it starts executing. Changing f1_x and f1_y within f1 do NOT change main_x and main_y.
February 3rd, 2008 at 11:57 pm
This is where …
This is where pass-by-reference is needed. If you actually *want* the called function to change main_x and main_y, you will have to pass it the “address-of” or “pointer-to” the actual variables so that it can change them.
In my example, f2 is actually designed in a way so that it can change the variable that was passed in.
To answer Xyaon’s question, if you pass by-value instead of by-reference, the function will only modify it’s local variables and the original variables will remain the same.
February 6th, 2008 at 7:10 am
I think that you’re …
I think that you’re referring to dangling pointers… If you don’t define a pointer it is initialised to 0xCCCCCCCC and if you attempt to dereference it (in a good IDE like VS) you’ll get a “Run-Time Check Failure”.
February 6th, 2008 at 7:13 am
Just incase anyone …
Just incase anyone learning is curious, these are two ways that dangling pointers can be produced (something that you should AVOID):
int* i = new int(3);
delete i;
*i = 5;
or
int* f()
{
int temp = 5;
return &temp;
}
February 9th, 2008 at 3:45 pm
So let me get this …
So let me get this straight. That * thing means refers to the address of whatever variable name it precedes (pointer). The & beside the variable name means the address of where the variable stores data?
February 11th, 2008 at 5:35 pm
A very wise C …
A very wise C programmer once told me…
“There are two types of C programmers, ones that don’t know pointers, and the successful ones that do.”