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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:19:33+00:00 2026-05-23T08:19:33+00:00

#include<stdio.h> #include<string.h> #include<iostream.h> using namespace std; int main() { const char *a=hello; char *b;

  • 0
#include<stdio.h>
#include<string.h>
#include<iostream.h>

using namespace std;

int main()
{
    const char *a="hello";
    char *b;
    strcpy(b,a);
     cout<<b;


    return 0;
}

This code theows memory exception . why ?

  • 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-23T08:19:34+00:00Added an answer on May 23, 2026 at 8:19 am

    char* b is a pointer that is yet to be pointed at any memory… it simply holds a random address. You attempt to copy the content of a over the memory at that address. Instead, first point b at some memory – either a local array or from new char[].

    char buffer[128];
    char* b = buffer;
    
    char* b = new char[128];
    // use b for a while...
    delete[] b; // release memory when you've finished with it...
              // don't read/write data through b afterwards!
    

    ( or simply copy it directly into buffer 🙂 )

    BTW, C++ has a <string> header that’s much, much easier to use:

    #include <string>
    
    int main()
    {
        std::string s = "hello";
        std::string t = s;
        std::cout << t << '\n';   // '\n' is a "newline"
    }
    

    If you’re writing new code, prefer std::string, but sooner or later you’ll need to know about all that char* stuff too, especially when C++ code needs to interact with C libraries.

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

Sidebar

Related Questions

#include <stdio.h> #include <string.h> #include <conio.h> #include <iostream> using namespace std; char a[21]; //
#include <stdio.h> #include <iostream> #include <stdlib.h> #include <string.h> using namespace std; void multiplier_matrice_vecteur (char
I have a simple program: #include <stdio.h> #include <iostream> using namespace std; int main(int
#include <iostream> #include <string> #include <regex> #include <ios> #include <locale> using namespace std; int
#include <string.h> #include <stdlib.h> #include <stdio.h> int main(void) { unsigned char *stole; unsigned char
#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { // int char str[40],ch; FILE*fp,*fp1,*fp2; fp=fopen(ide_input,w); fp1=fopen(error_log,w); fp2=fopen(lex_output,w);
#include<stdio.h> #include<zlib.h> #include<unistd.h> #include<string.h> int main(int argc, char *argv[]) { char *path=NULL; size_t size;
#include <stdio.h> #include <sys/shm.h> #include <sys/stat.h> #include <string> #include <vector> #include <iostream> using namespace
I'm getting compile error in this code #include<iostream> #include<cstdio> #include<string> using namespace std; void
Please see this piece of code: #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { int i

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.