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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:18:58+00:00 2026-06-17T08:18:58+00:00

I wrote a more complex program but I have narrowed down my problem to

  • 0

I wrote a more complex program but I have narrowed down my problem to the following one:
Why is this program printing down junk and not hzllo? I have followed the values and memory address of temp and p with the debugger and it returns from the foo function correctly and for a reason I don’t understand prints junk.

void foo(char **str) {
    char temp[79];
    strcpy_s(temp,79,*str);
    *(temp + 1) = 'z';

    *str = temp;    

}

void main() {

    char *p = (char*) malloc(79 * sizeof(char));
    p = "hello";
    foo(&p);

    printf("%s", p);
}
  • 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-17T08:18:58+00:00Added an answer on June 17, 2026 at 8:18 am

    Change

    char temp[79];        # allocated on the stack, vanishes on return
    

    …to…

    static char temp[79]; # has a longer lifetime
    

    Also, you don’t need the malloc(3).

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

Sidebar

Related Questions

Here's a more complex one for me: I have content like this being pulled
I have sqlite3.dll but I'm assuming it's far more complex than simply including that
I have one piece of Cocoa code I wrote that takes in an XML
I experienced this bug in a more complex application I am developing. I execute
I have a bit more complex system... I have users model - hasMany Ads
I have a problem with some JNI code. I'm getting the following error printed
I have a bit of a problem. I wrote an API a long time
I wrote a program to extract attachments from mail folders ( GITHUB ) but
I wrote some sort of console client for a simple application. To be more
I'm trying to write more efficient code in a C program, and I need

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.