Help:working of Type casting

This is a discussion on Help:working of Type casting within the C Programming forums, part of the General Programming Boards category; Code: main() { double d; printf("%d", (unsigned int)((double *)0+2)); } How the output of this code is 16?...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    6

    Unhappy Help:working of Type casting

    Code:
    main()
    {
        double d;
        printf("%d", (unsigned int)((double *)0+2));
    }
    How the output of this code is 16?
    Last edited by GOGO1104; 09-28-2010 at 12:07 PM.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    It's 16 due to pointer arithmetic. (double*)0+2 is the same as 0+2*sizeof(double).
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,761
    Didn't we just do this question in another thread?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing Argument from incompatible pointer type
    By AmritxD in forum C Programming
    Replies: 3
    Last Post: 08-15-2010, 04:23 PM
  2. Advantages of c++ type casting over c type casting
    By kaibalya2008 in forum C++ Programming
    Replies: 10
    Last Post: 05-05-2009, 12:09 PM
  3. type casting void *
    By Alexpo in forum C Programming
    Replies: 5
    Last Post: 06-23-2008, 04:05 AM
  4. Replies: 0
    Last Post: 03-20-2008, 08:59 AM
  5. Erros in Utility Header File
    By silk.odyssey in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2003, 06:17 AM

Tags for this Thread


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