Thread: basic C operator question

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    25

    basic C operator question

    Hi guys

    I'm playing with some operator to get the hang of it. I have defined
    i=1 ;
    g=5;
    y is the output variable

    now I'm trying to get certain numbers:

    y=(3!=9)+ (i++)+ (19%5) is supposed to give 7, but it gives me 9!

    y= ((3>7)|| (4<3)) + g +(i++) gives me 10 instead of 8, which I'm looking for

    can you find where my problem is?
    thanks

  2. #2
    Registered User
    Join Date
    Sep 2012
    Posts
    357
    Code:
    i = 1;
    g = 5;
    y = (3 != 9) + (i++) + (19 % 5);
    // (  1  ) + ( 1 ) + (  4   )         and i became 2
    // y = 6;
    y = ((3 > 7) || (4 < 3)) + g + (i++);
    //  ((  0  ) || (  0  )) + 5 + ( 2 )         and i became 3
    //  (        0       ) + 5 + ( 2 )
    // y = 7;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-23-2011, 09:00 AM
  2. Fix basic error: no match for 'operator!=' in 'i != ...
    By aeolusaether in forum C++ Programming
    Replies: 7
    Last Post: 04-04-2010, 12:27 AM
  3. Basic operator overloading question
    By Swerve in forum C++ Programming
    Replies: 5
    Last Post: 11-20-2009, 12:44 PM
  4. C++ Basic Question
    By MaGaIn in forum C++ Programming
    Replies: 11
    Last Post: 09-18-2007, 06:29 PM
  5. Basic C question '\n'
    By mervin in forum C Programming
    Replies: 9
    Last Post: 01-19-2002, 08:57 PM