Thread: Basic typecasting

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    22

    Basic typecasting

    I'm a bit stumped in trying to cast a very basic int division to a long result and the irony is that I've managed to use typecasting from float to long with complex equations. I just can't seen what's wrong with this...

    Code:
    int main(){
    
            int initVol = 40;
            int intIndex;
            long longIndex;
    
            intIndex = initVol / 100;
            printf("int index = %d, ");
            longIndex = (long) ( initVol / 100 );
            printf("long index = %d.\n");
    
            return 0;
    }
    Both intIndex and longIndex give the wrong answer. But why? I would have expected intIndex to be correct at the very least.

  2. #2
    Registered User
    Join Date
    Sep 2015
    Posts
    22
    Flipping heck, could I be so dumb! I've just figured it out. Never mind folks. Just point and quietly chuckle.

  3. #3
    spaghetticode
    Guest
    Quote Originally Posted by SqueezyPeas View Post
    Just point and quietly chuckle.
    No need to. You've made a very common mistake, put some effort to find it, finally found it. Everything's fine. Plus I bet this will never happen to you again. Time for some backslapping.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Typecasting
    By ItzBlue in forum C Programming
    Replies: 2
    Last Post: 12-31-2014, 08:29 PM
  2. Typecasting
    By ~Kyo~ in forum C++ Programming
    Replies: 3
    Last Post: 05-10-2011, 05:56 PM
  3. typecasting
    By eklavya8 in forum C Programming
    Replies: 9
    Last Post: 01-03-2009, 09:02 AM
  4. typecasting
    By sreetvert83 in forum C++ Programming
    Replies: 7
    Last Post: 07-22-2005, 01:55 PM
  5. typecasting
    By v6sa in forum C++ Programming
    Replies: 2
    Last Post: 05-08-2005, 04:01 AM

Tags for this Thread