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 8361629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:44:25+00:00 2026-06-09T11:44:25+00:00

I have a c++ vector: vector<float> floats; Later, this vector is initialized. I don’t

  • 0

I have a c++ vector:

        vector<float> floats; 

Later, this vector is initialized. I don’t know what the internal contents of the vector container are, but I want to know if it is possible to return a pointer to where the array of floats are. Specifically, I am using CUDA and I need to pass a pointer to an array of floats. I cannot pass it a vector. Is there a way I can do something like

float *dapointer = &vector[0];

or something like this? I want to be able to write to it as well, like

dapointer[some index] = 4;

I realize this violates the point of a vector, but this vector is used for “vector purposes” in many other places in the program, but I need CUDA to be able to access the data as well. I don’t want to change all my other code around to use an array instead of a vector.

  • 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-06-09T11:44:26+00:00Added an answer on June 9, 2026 at 11:44 am

    The approach should work, but be careful. Upon modifications to the vector, you might be left with dangling pointers. non-const operations performed on a vector invalidate iterators, pointers & references to memory it manages. On way to make this safe is marking the vector const.

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

Sidebar

Related Questions

I have vector< pair<int, int>> myVec (N); I want to have all pairs initialized
I have the vector d<-1:100 I want to sample k=3 times from this vector
Let's I have struct Vector { float i,j,k; } I want to zero all
I have a vector of float arrays i.e. Vector . I want to convert
I have this code void split(vector<float> &fvec, string str) { int place = 0;
I have a vector of floats, defined by: std::vector<float>* MyVec; and I was filling
I have two vectors of floats and i want them to become one vector
I have a struct that looks like this: typedef struct _my_struct { float first_vector[SOME_NUM][OTHER_NUM];
I have a boost::unordered_multimap< std::vector<int>, float> . The keys that I use to query
I have the vector output = PV_out(:); I am trying to break this down

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.