basic C operator question

This is a discussion on basic C operator question within the C Programming forums, part of the General Programming Boards category; Hi guys I'm playing with some operator to get the hang of it. I have defined i=1 ; g=5; y ...

  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
    qny
    qny is offline
    Registered User
    Join Date
    Sep 2012
    Posts
    355
    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, 10: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, 01: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, 07:29 PM
  5. Basic C question '\n'
    By mervin in forum C Programming
    Replies: 9
    Last Post: 01-19-2002, 08:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21