Thread: pointer cast flot

  1. #1
    Registered User
    Join Date
    Nov 2022
    Posts
    3

    pointer cast flot

    How does this pointer cast address work


    float f = 1.83;
    unsigned int i = *( const unsigned int *) &f ;

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > unsigned int i = *( const unsigned int *) &f ;

    & - make a pointer of type float*
    ( const unsigned int *) - make believe that it's a pointer to a const unsigned int.
    * - dereference it to get an unsigned int.
    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.

  3. #3
    Registered User
    Join Date
    Nov 2022
    Posts
    3
    this is & address.

  4. #4
    Registered User
    Join Date
    Nov 2022
    Posts
    3
    why use const?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Quote Originally Posted by kers View Post
    why use const?
    No particular reason, it doesn't make a difference in this case.
    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. Replies: 15
    Last Post: 01-01-2022, 12:05 PM
  2. Cast a struct pointer to an array pointer
    By bremenpl in forum C Programming
    Replies: 1
    Last Post: 12-03-2015, 07:06 AM
  3. Replies: 3
    Last Post: 03-27-2014, 12:10 AM
  4. pointer w/o a cast.
    By chrismiceli in forum C Programming
    Replies: 3
    Last Post: 03-26-2003, 07:18 PM
  5. pointer w/o cast
    By chrismiceli in forum C Programming
    Replies: 1
    Last Post: 03-25-2003, 06:32 PM

Tags for this Thread