simple program

This is a discussion on simple program within the C Programming forums, part of the General Programming Boards category; [hi all, i am new to this and not very sure if the code i write is correct..anw, my com ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    11

    simple program

    [hi all, i am new to this and not very sure if the code i write is correct..anw, my com doesnt have Visual C++ so i cant complie and check..must wait till i return school on monday.. i have written a code and it sound correct to me...would really be thankful if anyone could just take a look at it and help me check if i have made any mistakes

    the below is a code to use the bitwise AND operation (ea12 ∩ 1201)

    Code:
    #include <stdio.h>
    #define AND &&
    
    int main(void)
    
    { float output;
    
    output = 0xea12 && 0X1201 ;
    printf("The output is %f", output );
    
    return0;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,271
    i am new to this and not very sure if the code i write is correct..anw, my com doesnt have Visual C++ so i cant complie and check..must wait till i return school on monday.. i have written a code and it sound correct to me...would really be thankful if anyone could just take a look at it and help me check if i have made any mistakes
    You can download and use Microsoft Visual C++ 2008 Express for free. Asking people to help you compile and test online would be rather tedious, not to mention slow. Also, you would lose out on the practice of using the compiler and IDE yourself, which may be a factor if you have to compile and debug during a lab test.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Nub SWE
    Join Date
    Mar 2008
    Location
    Dallas, TX
    Posts
    133
    Code:
    output = 0xea12 && 0X1201 ;
    When you get to class on Monday, I would look at this line in particular.

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    11
    thanks alot!!! anw, wanted to know if the code sounds logical...thanks laserlight =)

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    11
    JDGARX... this line is wrong?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,271
    wanted to know if the code sounds logical
    Well, why is output a float instead of an int (or _Bool)?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Mar 2008
    Posts
    11
    oh, okie noted...actually i not sure if i shd put float or int..

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,271
    actually i not sure if i shd put float or int
    What is the difference between float and int, and what are the kind of values that the expression (x && y) evaluates to?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Mar 2008
    Posts
    11
    the output shd be an int...yup. so i change accordingly. thanks alot =)

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,271
    Remember to update the format specifier for printf()
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a very simple program
    By htdefiant in forum C++ Programming
    Replies: 13
    Last Post: 08-14-2007, 02:27 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 01:27 PM
  3. [Help] Simple Array/Pointer Program
    By sandwater in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 03:42 PM
  4. simple silly program
    By verbity in forum C Programming
    Replies: 5
    Last Post: 12-19-2006, 06:06 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM

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