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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:05:36+00:00 2026-06-07T01:05:36+00:00

Pointers have always made me blank about the logic I intend to use in

  • 0

Pointers have always made me blank about the logic I intend to use in code, If someone can help me understand a few concepts that would be really helpful. Here’s a code snippet from my program,

vector <char> st; 
char *formatForHtml(string str, string htmlTag)
{ 
    string strBegin;
    strBegin = "<";
    strBegin.append(htmlTag);
    strBegin.append(">");
    strBegin.append(str);
    string strEnd = "</";
    strEnd.append(htmlTag);
    strEnd.append(">");
    strBegin.append(strEnd);
    st.resize(strBegin.size());
    for (int i =0;i <strBegin.size();i++) {
        st[i] = strBegin.at(i);
    }
    return &st[0];
}

In the code above if I have to return address of st[0], I have to write the function of type char *. I need to know the reason to do so, also if address is the integer value why can I not define function as an int type?

P.S. It’s a beginner level doubt.

  • 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-07T01:05:38+00:00Added an answer on June 7, 2026 at 1:05 am

    I have to write the function of type ‘char *’ I need to know the reason to do so

    There’s no reason to do so. Just return a std::string.

    From the looks of your code, st is a std::vector<char>. Since std::vector has continuous memory, &st[0] is the address of the first char in the vector, and thus points to the not null-terminated string that the vector represents, which isn’t very helpful outside the function because you can’t find the length.

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

Sidebar

Related Questions

I have an odd question that I have always thought about, but could never
C++ references have two properties: They always point to the same object. They can
I know that javascript doesn't have pointers in terms of a variable referring to
I have two pointers, char *str1; int *str2; If I look at the size
Does anyone have any pointers to good resources concerning mesh networks? Maybe I'm not
I have to make a horizontal month slider which will have two pointers which
I'm a Java programer lost in C++ and pointers :D I have an array
I have worked with pointers a lot, but still whenever I work with them,
I have two unmanaged pointers in the form of IntPtr and want to copy
I have a list of pointers that reference time objects that need a turn

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.