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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:34:47+00:00 2026-06-11T10:34:47+00:00

char * p_one = this is my first char pointer; char * p_two= this

  • 0
char * p_one = "this is  my first char pointer";
char * p_two= "this is second";
strcpy(p_one ,p_two);

consider the above code. This is giving access violation error.
So please help to understand

  1. where is the current "this is my first char pointer" string stored in memory? heap or stack
  2. why I need to allocate memory for p_one before call strcpy, even it’s already storing the first string. why "this is second" string cannot copy to same location?
  3. If I allocate memory for p_one before call strcpy then what happen to "this is my first char pointer" string that was pointed by p_one ? is it keep in memory?
  4. How strcpy knows specific pointer have allocated memory or not?
  • 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-11T10:34:48+00:00Added an answer on June 11, 2026 at 10:34 am

    First off your compiler should be warning that the p_one and p_two are actually const char * because the compiler allocates the storage of this string at compile time.

    The reason you cannot modify them is because in theory you could overwrite memory after them, this is what causes hack attack with a stackoverflow.

    Also the compiler could be smart and realize that you you use this string in 10 places but notices it is the same, so modifying from one place changes it – but that destroys the logic of the other 9 places that uses it

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

Sidebar

Related Questions

char p[4]={'h','g','y'}; cout<<strlen(p); This code prints 3. char p[3]={'h','g','y'}; cout<<strlen(p); This prints 8. char
This code causes a Segmentation Fault: int main(){ char *p; char a[50] = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
Why the following code works: char *p; p=hello; printf(%s\n,p); While this one doesn't: char
Where do I edit this code to find the first letter of each word
This question is related to this one . Given this code: char *p =
I'm trying to access a dll from python, following this guide . The first
int main() { char *p,c; for(p=Hello World;c=*p;++p) { printf(%c,c); } } In the above
How to prove const char *p is same as char const *p through code
// The first example: char text[] = henri; char *p; p = text; *(p
I'm having problems getting this code to populate output parameters with MSSQL ODBC 10.0

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.