CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 27

Thread: a = b; Help?

  1. #1
    Join Date
    Mar 2009
    Posts
    5

    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

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: a = b; Help?

    Take your best guess. You'll probably be right.

  3. #3
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Lightbulb Re: a = b; Help?

    I think (but I'm not sure) that it means that a equals b... but I could be wrong.

  4. #4
    Join Date
    Feb 2002
    Posts
    3,788

    Re: a = b; Help?

    Quote Originally Posted by skizmo View Post
    i think (but i'm not sure) that it means that a equals b... But i could be wrong.

  5. #5
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: a = b; Help?

    Quote Originally Posted by iPirate View Post
    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...

  6. #6
    Join Date
    Mar 2009
    Posts
    5

    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.

  7. #7
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: a = b; Help?

    [ Moved thread ]
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  8. #8
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    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&#37;2B%2B

  9. #9
    Join Date
    Aug 2005
    Location
    San Diego, CA
    Posts
    1,054

    Lightbulb Re: a = b; Help?

    Quote Originally Posted by iPirate View Post
    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.

  10. #10
    Join Date
    Apr 2009
    Posts
    21

    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.

  11. #11
    Join Date
    Mar 2009
    Posts
    5

    Re: a = b; Help?

    Quote Originally Posted by kempofighter View Post
    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.

  12. #12
    Join Date
    Apr 2009
    Posts
    21

    Re: a = b; Help?

    yo,

    if you ever get stuck on anything, feel free to send me a pm, etc.

  13. #13
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: a = b; Help?

    Quote Originally Posted by EsX_Raptor View Post
    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.

  14. #14
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: a = b; Help?

    Quote Originally Posted by EsX_Raptor View Post
    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...
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  15. #15
    Join Date
    Apr 2009
    Posts
    21

    Re: a = b; Help?

    lol this sites got the pms blocked

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured