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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:31:11+00:00 2026-06-18T18:31:11+00:00

Hee guys, I have been reading a couple of things about pointers and pointees

  • 0

Hee guys,

I have been reading a couple of things about pointers and pointees and started getting curious. The only thing I dont understand is how pointers behave in functions, hence the following code:

#include <stdio.h>

int pointeeChanger(char* writeLocation) {

    writeLocation = "something";
    return 0;
}

int main(void)
{

    char crypted[] = "nothing";
    char* cryptedPointer = crypted;

    pointeeChanger(cryptedPointer);

    printf("The new value is: %s", cryptedPointer);

    return 0;
}

What my intention to do is to adjust the pointee, “crypted” var, through a pointer given to a function. The only thing is that it is not working. Could you please explain me what is going wrong in my thought process. I am fairly new to C so my errors could be fairly basic.

Thanks in advance!

Greetings,

Kipt Scriddy

  • 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-18T18:31:12+00:00Added an answer on June 18, 2026 at 6:31 pm

    Short answer: writeLocation is a local variable and is a copy of cryptedPointer. When you modify writeLocation, cryptedPointer is not modified.

    If you want to modify cryptedPointer, you have to pass a pointer to it, like so:

    #include <stdio.h>
    
    int pointeeChanger(char** writeLocation) {            /* Note: char** */
    
        *writeLocation = "something";                     /* Note: *writeLocation */
        return 0;
    }
    
    int main(void)
    {
    
        char crypted[] = "nothing";
        char* cryptedPointer = crypted;
    
        pointeeChanger(&cryptedPointer);                  /* Note: &cryptedPointer */
    
        printf("The new value is: %s", cryptedPointer);
    
        return 0;
    }
    

    There are other issues with this code though. After the call to pointeeChanger(), cryptedPointer no longer points to the crypted array. I suspect you actually wanted to change the contents of that array. This code fails to do that.

    To change the value of crypted[] you will need to use strcpy() or (preferably) strncpy(). Also you will need to watch the size of the crypted[] array – "something" is longer than "nothing" and will cause a buffer overflow unless crypted[] is made larger.

    This code will modify the original crypted[] array:

    #include <stdio.h>
    #include <string.h>
    
    #define MAX_STR_LEN 64
    
    /*
     * Only char* required because we are not modifying the
     * original pointer passed in - we are modifying what it
     * points to.
     */
    int pointeeChanger(char* writeLocation)
    {
        /*
         * In C, you need to use a function like strcpy or strncpy to overwrite a
         * string with another string. Prefer strncpy because it allows you to
         * specify a maximum size to copy, which helps to prevent buffer overruns.
         */
        strncpy(writeLocation, "something", MAX_STR_LEN);
    
        /* strncpy doesn't automatically add a \0 */
        writeLocation[MAX_STR_LEN] = '\0';
    
        return 0;
    }
    
    
    int main(void)
    {
        /*
         * The +1 is because an extra character is required for the 
         * null terminator ('\0')
         */
        char crypted[MAX_STR_LEN + 1] = "nothing";
    
        pointeeChanger(crypted);
    
        printf("The new value is: %s", crypted);
    
        return 0;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hee, I'm kinda new to Qt and i started to add UnitTests to my
Hee Does anybody know how to check in-application if a mail account is setup
Really a buggy question , hee is the code: import java.io.IOException; import java.security.*; import
I'm following the Rails Tutorial to get started (for the 4000th time) with Ruby
Hee Does anybody know how to recognize a multitask-kill. When the user puts the
Hee Does anybody know how to implement an method in objective c that will
this is a case again where I'm running around in circles and I'm about
My file has this structure: HELLO h e l lo HELLO(2) h ee l
Does google maps api use an older verison of their maps? When I embed
Ok I do understand how Java Reflection works. But what I am doing is

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.