C pointer query

Discussion in 'C Programming' started by ashuosh, Jul 18, 2014.

  1. ashuosh

    ashuosh

    Joined:
    Jul 18, 2014
    Messages:
    1
    Likes Received:
    0
    I don't pointer and array arithmetic can any body will help me in all the details of pointer and array arithmetic along with examples programs.

    Q1: Multiplication of pointer and unsigned integer is allowed how and why?
    Q2: address of float can be assigned to a char pointer?
     
    ashuosh, Jul 18, 2014
    #1
    1. Advertisements

  2. ashuosh

    ruchi chouhan

    Joined:
    Feb 12, 2018
    Messages:
    1
    Likes Received:
    0
    ans2.


    You can indeed treat every object as an array of characters. However, you have to cast the pointer explicitly:

    float f = 1.5f;

    char const * p = (char const *)&f;

    for (size_t i = 0; i != sizeof(float); ++i)
    {
    printf("The byte at position %zu has value %d.\n", i, (int)p);
    }
     
    ruchi chouhan, Feb 12, 2018
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.