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

  • Home
  • SEARCH
  • 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 8319535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:21:27+00:00 2026-06-08T22:21:27+00:00

Whenever I am using one of these functions in dev-C++(I know its old but

  • 0

Whenever I am using one of these functions in dev-C++(I know its old but for some reason still taught at my college.)

strcat,strcpy,strcmp,strchr...//And their variants stricmp...

The first argument for these functions always has to be an array (i.e:

char ch[]="hello";

But it can’t be a pointer to a string bc for some reason this causes a crash.
In fact for an example look at both of these codes:

code1:

#include<stdio.h>
#include<string.h>
main()
{char ch[20]="Hello world!";
 char *ch2="Hello Galaxy!";
 strcat(ch,ch2);
 printf("%s",ch);
 scanf("%d")//Just to see the output.
}

This code works fine and gives the expected result(Hello World!Hello Galaxy!)

But the inverse code2 crashes.

code2:

#include<stdio.h>
#include<string.h>
main()
{char ch[20]="Hello world!";
 char *ch2="Hello Galaxy!";
 strcat(ch2,ch);
 printf("%s",ch2);
 scanf("%d")//Just to see the output.
}

This code crashes and causes a

file.exe has stopped working Error.

This is the same for almost all of the strings functions that takes two arguments.
What is the cause of this problem.

  • 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-08T22:21:29+00:00Added an answer on June 8, 2026 at 10:21 pm

    With char *ch2 = "Hello Galaxy!"; you are obtaining a pointer to a string literal. You should never attempt to modify a string literals, as this invokes undefined behaviour (which in your case has manifested as a crash).

    With char ch[20] = "Hello World!"; you are initialising an array using the contents of a string literal, so you end up with your own modifiable copy of the string in ch.

    Also, note that 20 characters is not enough for Hello World!Hello Galaxy! to fit, and this is also undefined behaviour, and known as overflowing your buffer.

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

Sidebar

Related Questions

Started using Visual Studio 2012 RC since yesterday, We have one WCF solution. Whenever
Whenever I try installing anything using gem, I get this error - murtaza@murtaza-dev:~$ sudo
I'm using opencsv in my application but whenever I try to read my csv
(Note: I'm using jQuery below, but the question is really a general JavaScript one.)
Whenever i try using php with lighttpd on my iphone i get error 500
Whenever I specify a resource using the Spring Data Hadoop namespace, by application throws
Whenever I start a shell in vim using :sh, it doesn't source my ~/.bashrc
I'm using ASP.Net and whenever I create a script file or try to include
Im using the endless adapter http://github.com/commonsguy/cwac-endless however whenever i return false (because i dont
i'm using the DOMdocument class in php whenever i want to create a XML

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.