-
April 21st, 2009, 01:21 PM
#1
a = b; Help?
Ok im a bit stuck with Operators. I have this code, but dont know what some parts mean.
Code:
#include <iostream>
using namespace std;
int main ()
{
int a, b=3, c=1, d=5;
a = b; << What do these parts mean?
c = d; << ???
c+=1;
d+=2;
cout << d;
cin.get();
return 0;
}
Thank you!
Last edited by ovidiucucu; April 21st, 2009 at 01:49 PM.
Reason: [CODE] tags added
-
April 21st, 2009, 01:24 PM
#2
Re: a = b; Help?
Take your best guess. You'll probably be right.
-
April 21st, 2009, 01:28 PM
#3
Re: a = b; Help?
I think (but I'm not sure) that it means that a equals b... but I could be wrong.
-
April 21st, 2009, 01:32 PM
#4
-
April 21st, 2009, 01:34 PM
#5
Re: a = b; Help?
Originally Posted by iPirate
Ok im a bit stuck with Operators. I have this code, but dont know what some parts mean.
a = b; << What do these parts mean?
c = d; << ???
Really? From that entire program THESE two lines are most confusing???
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
April 21st, 2009, 01:44 PM
#6
Re: a = b; Help?
Oh, i see.
Sorry i understand now.
The noob i am.
Last edited by iPirate; April 21st, 2009 at 01:47 PM.
-
April 21st, 2009, 01:46 PM
#7
-
April 21st, 2009, 01:47 PM
#8
Re: a = b; Help?
This is so incredibly basic that I had trouble finding a page on it that wasn't going to confuse you further by referring to class operator overloading and the like, but this one comes pretty close:
http://en.wikipedia.org/wiki/Assignm...in_C%2B%2B
-
April 21st, 2009, 01:49 PM
#9
Re: a = b; Help?
Originally Posted by iPirate
Yes, I dont understand what they do.
Add some cout statements before and after those two lines of code such as:
std::cout << "a = " << a << std::endl;
std::cout << "b = " << b << std::endl; // and so forth
This will tell you the before and after values for each variable. Also, you could compile and run the program. Step into the program with the debugger and analyze the values before and after the statements.
-
April 21st, 2009, 01:54 PM
#10
Re: a = b; Help?
I recommend you pick up a really, really basic (for super beginners) book on C/C++.
Anyways.
Think of a, b, and c as memory locations because in C/C++ that's what they are.
e.g.
Whenever you:
int a;
You're allocating a space in memory with label "a" and type int (integer).
When you see the expression:
a = b;
The "=" doesn't mean "equals" but it rather means "is assigned" so if we translate it would read:
"a is assigned b"
If you still don't understand, what that statement does is that it takes anything that is currently allocated in the left side of the operator (=) and assigns it whatever is located on the right side.
I hope this helps.
-
April 21st, 2009, 02:00 PM
#11
Re: a = b; Help?
Originally Posted by kempofighter
Add some cout statements before and after those two lines of code such as:
std::cout << "a = " << a << std::endl;
std::cout << "b = " << b << std::endl; // and so forth
This will tell you the before and after values for each variable. Also, you could compile and run the program. Step into the program with the debugger and analyze the values before and after the statements.
Ah thanks
Also i know how Variables work etc.
Just i didnt know what a = b meant, until now of course.
-
April 21st, 2009, 02:15 PM
#12
Re: a = b; Help?
yo,
if you ever get stuck on anything, feel free to send me a pm, etc.
-
April 21st, 2009, 02:33 PM
#13
Re: a = b; Help?
Originally Posted by EsX_Raptor
yo,
if you ever get stuck on anything, feel free to send me a pm, etc.
That kind of defeats the point of the forum. The advantage to keeping it public is we can monitor and correct each other when necessary, and provide potentially better solutions. Even those of us with thousands of posts make mistakes, and it's good to have other people there to catch them.
-
April 21st, 2009, 02:33 PM
#14
Re: a = b; Help?
Originally Posted by EsX_Raptor
yo,
if you ever get stuck on anything, feel free to send me a pm, etc.
Yo, I wold like to ask it in the forum...
-
April 21st, 2009, 04:43 PM
#15
Re: a = b; Help?
lol this sites got the pms blocked
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|