Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6714429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:29:42+00:00 2026-05-26T08:29:42+00:00

If I have this reference variable: float* image How can I get the length

  • 0

If I have this reference variable:

float* image

How can I get the length of this image in C? The length = (width * height) but how can I get this value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:29:43+00:00Added an answer on May 26, 2026 at 8:29 am
    float * image
    

    Simply points at a single float. It can also be used with array syntax — ie image[n] to get the nth float from the location of image. People will use pointers and malloc to create a dynamic array of floats. However, there’s no information associated with the size stored with the data itself. That’s a detail the coder has to care about in C. Often in these kinds of cases in C when you’re passed such a pointer in a function, you’re also passed an accompanying size, ie:

    void Foo(float* image, size_t numFloatsInImage)
    

    It sounds like though that image might point to a block of contiguous memory treated as a 2d array. That is something with a width and height. So instead of strictly a numberOfFloats you might have something like this “3×3” image:

    
        image ->  0  1  2  3  4  5  6  7  8
                  0  0  0  1  1  1  2  2  2
    

    There’s a total of 3×3 == 9 floats here with the first 3 corresponding to row 1, the next 3 row 2, and the last one as row 4. This is simply a single dimensional array used to represent 2d data.

    Like I said before, this is a detail of how you’ve decided to use the language and not a part of it. You’ll have to pass along the width/height with the pointer for safe use:

    void Foo(float* image, size_t width, size_t height)
    

    You can also avoid this by simply creating a struct to store your image, being sure to always initialize/maintoin the width and height correctly

     struct
     {
         float* image; // points to image data
         size_t width;
         size_t height;
     };
    

    then always pass around the struct to functions like foo

    Another trick could be to overallocate float to store the width and height in the buffer itself:

     float* image = malloc(width*height + 2);
     image[0] = width;
     image[1] = height;
     // everything past image[2] is image data
    

    In any case, there’s these and many other implementation specific ways to store/pass this data. Whoever is giving you this pointer should be telling you how to get the length/height and telling you how to use the pointer. There’s no way C can figure out how it’s being done, its an implementation decision.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using this as a reference, but not able to accomplish exactly
I have read Java Concurrency in Practice and this is a great reference, but
i have 3 hidden fields in 1 div. when I have reference to this
What does this mean: Next add reference to: MySql.Data actually I have downloaded mysql
We have a service reference that points at a WCF service, this acts as
I have a class whose constructor takes a const reference to a string. This
I have a list of error codes I need to reference, kinda like this:
I have this code in cuda with c++: // Variables float *query_dev; float *ref_dev;
I have a reference to an object. This object has a timer event with
Possible Duplicate: Difference between pointer variable and reference variable in C++ I saw this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.