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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:10:12+00:00 2026-06-18T12:10:12+00:00

class A { char *name; public: A(); A(char*); ~A(); }; A::A() { } A::A(char*

  • 0
class A
{
    char *name;
public:
    A();
    A(char*);
    ~A();
};

A::A()
{

}
A::A(char* s)
{
    int k=strlen(s);
    name=new char[k+1];
    strcpy_s(name,k+1,s);
}
A::~A()
{
    if(name!=NULL)
        delete[] name;
}

int _tmain(int argc, _TCHAR* argv[])
{
    A *v=new A[20];
    delete[] v;
    system("pause");
    return 0;
}

I get the following error at runtime: Unhandled exception at 0x5B987508 (msvcr110d.dll) in test212.exe: 0xC0000005: Access violation reading location 0xCDCDCDC1.
It’s obviously a memory problem, but can you please tell me what happens in this example of code?

  • 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-18T12:10:13+00:00Added an answer on June 18, 2026 at 12:10 pm

    new A[20] calls the default constructor, and you don’t initialize name in the default constructor. You can’t assume that it will be set to NULL for you. In the absence of initialization, delete[] name has undefined behaviour.

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

Sidebar

Related Questions

class User { public: User(char *name,char *pass) { strncpy(username[num],name,strlen(name)); username[num][strlen(name)]='\0'; for(int i=0;i<strlen(pass);i++) password[num][i]=(i+pass[i])%256; password[num][strlen(pass)+1]='\0';
#include<stdio.h> #include<fstream.h> class Test { char name[10]; int data; public: void getData() { cin>>name;
Given a class such as: class Person { private: char *name; public: Person() {
public class GamePiece { public GamePiece(char cLetter, int nPointValue) { m_cLetter=cLetter; m_nPointValue=nPointValue; m_nTurnPlaced=0; //has
I have class Person as following : class Person { char* name; int age;
Please have a glance at this program: class CopyCon { public: char *name; CopyCon()
Here is the program... class CopyCon { public: char *name; CopyCon() { name =
#include<iostream> #include<cstring> using namespace std; class Employee { char name[5]; int id; int age;
using UnityEngine; using System.Collections; public class objectControl : MonoBehaviour { public char slected_item =
#include <iostream> using namespace std; class Marks { public: char* name(); }; char* Marks::name()

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.