Results 1 to 10 of 14

Thread: [C] The lousy random question thread

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    Thank you ^___^

    i talked to you (kung) in xfire, and at this ime i understood this snippit:
    Code:
    float x = 10.3;
    void *p;
    p = (float *)&x;
    *(float *)p = 100.001;
    but for now, i dont get the 3rd line..
    p is a void* and gets an address assigned from a floating point number, which is casted to a float*
    a void* can contain a float* without any troubles? (yh, maybe the compiler knows how to handle this, but i want to learn how to do it correctly)

    if i initialise a void* p; on startup, does p always stay a void* or is this possible = (int *)p; to cast the variable itself to another pointer-type? (same with normal types: int i = 1; i = (float)i

    i just re-read you answer:
    Code:
        int i = 4;
        printf("%d", *&*&*&*&i); // prints 4
        // thats the same:
        printf("%d", *(int *)&*&i); // 4
    i assume on here that (int *)&i == &i am i correct?
    and if so, thn on my first example (float *)&x == &x means, &x still is a float* and thn there is no need for doing a cast b4?

    yh, i know, ima N00b, but if youre willing to answer me, feel free to
    have fun :'D
    Last edited by serthy; 1st April 2013 at 13:03.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •