Thread: Help:working of Type casting

  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 11:07 AM.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    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.

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, 03: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, 11:09 AM
  3. type casting void *
    By Alexpo in forum C Programming
    Replies: 5
    Last Post: 06-23-2008, 03:05 AM
  4. Replies: 0
    Last Post: 03-20-2008, 07: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