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

  • SEARCH
  • Home
  • 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 4266496
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:46:05+00:00 2026-05-21T06:46:05+00:00

I am trying to learn a little c++ and I have a silly question.

  • 0

I am trying to learn a little c++ and I have a silly question. Consider this code:

TCHAR tempPath[255];
GetTempPath(255, tempPath);

Why does windows need the size of the var tempPath? I see that the GetTempPath is declared something like:

GetTempPath(dword size, buf LPTSTR);

How can windows change the buf value without the & operator? Should not the function be like that?

GetTempPath(buf &LPTSTR);

Can somebody provide a simple GetTempPath implementation sample so I can see how size is used?

EDIT:

Thanks for all your answers, they are all correct and I gave you all +1. But what I meant by “Can somebody provide a simple GetTempPath implementation) is that i have tried to code a function similar to the one windows uses, as follow:

void MyGetTempPath(int size, char* buf) 
{
 buf = "C:\\test\\";
}

int main(int argc, char *argv[])
{
    char* tempPath = new TCHAR[255];
    GetTempPathA(255, tempPath);
    MessageBoxA(0, tempPath, "test", MB_OK);
    return EXIT_SUCCESS;
}

But it does not work. MessageBox displays a “##$’ string. How should MyGetTempPath be coded to work properly?

  • 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-21T06:46:06+00:00Added an answer on May 21, 2026 at 6:46 am

    Windows needs the size as a safety precaution. It could crash the application if it copies characters past the end of the buffer. When you supply the length, it can prevent that.

    Array variables work like pointers. They point to the data in the array. So there is no need for the & operator.

    Not sure what kind of example you are looking for. Like I said, it just needs to verify it doesn’t write more characters than there’s room for.

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

Sidebar

Related Questions

I am trying to learn MySQL select statements a little better and I have
I'm trying to do a little PDO CRUD to learn some PDO. I have
I'm trying to learn reverse engineering, and I'm stuck on this little thing. I
I'm trying to learn C++ so forgive me if this question demonstrates a lack
I have just started trying to learn Git and I have got a little
I am trying to learn how to use rand_r, and after reading this question
I'm trying to learn a little bit C++ and Boost.Asio. I'm trying to compile
I am working on a little mini compiler while trying to learn some MIPS
Trying to learn a bit about PDO and is going through this tutorial .
Trying to learn about php's arrays today. I have a set of arrays like

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.