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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:29:21+00:00 2026-06-14T10:29:21+00:00

I am getting access violation error in the below code..i have pointed it out

  • 0

I am getting access violation error in the below code..i have pointed it out in the program.

void *pBuff = 0;

void set_data(void *pBuff)
{
    int value = 70, i;
    int *phy_bn = new int[8];

    for(i=0; i<8; i++)phy_bn[i] = value;

    pBuff =phy_bn;
    cout<<((int*)pBuff)[0];//..accessing 0th element value..no error here..gives 70 as result..
}


int main()
{
    set_data(pBuff);
    cout<<((int*)pBuff)[0];//acces violation error
    return 0;
}

Why that access violation even when i am not assigning it the address of a local variable…

Yes i can use vector or pass by reference.

But i want to know why pBuff is not getting assigned

  • 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-14T10:29:23+00:00Added an answer on June 14, 2026 at 10:29 am

    When you say

    pBuff = phy_bn;
    

    You’re just changing the local value of pBuff, not the global value of pBuff. Either pass pBuff as a double pointer, or simply remove the argument to the function, as pBuff is global already.

    void *pBuff = 0; /* This is the global pBuff, which isn't being changed */
    
    void set_data(void *pBuff /* This is the local pBuff, which is being changed */)
    {
        ...
        pBuff = phy_bn;
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting an unexpected Access Violation error in the following code: program Project65;
I'm getting access violation while writing error in the below code while putting null
Iam getting access violation error while I am performing debugging in stereo calibration code
I am getting access violation error when I run the following code on Visual
I am getting the error, SQLSTATE[42000]: Syntax error or access violation: 1064 You have
I am getting Access violation error from the debugger, but I really have no
I'm getting a (to me) weird run-time access violation error. I have a class,
Hi I am getting an access violation error..... What might be the problem in
I am getting an error: Message: SQLSTATE[42000]: Syntax error or access violation: 1064 You
I am getting an access violation error in an unmanaged dll I am writing,

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.