I want to change the contents of a constant-character-array(const array[64]).
Below is my code.
My Question is, why does the constant character array doesn’t change(not reflected back), when passed to the function as constant character pointer(const char *append)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int function(char *d,const char *append)
{
append = d; //changing the location of append.
printf ("%s\n",append); //displays as sachintendulkar.
}
int main()
{
char *d = NULL;
const char append[]={'s','a','c','h','i','n'};
d = calloc(sizeof(char),sizeof(append));
strcpy(d,append);
strcat(d,"tendulkar"); //appending
function(d,append);
printf ("%s\n",append); //Its displays as sachin instead of sachintendulkar???
}
Function arguments are passed by value, when you assign a new value to the pointer
appendinsidefunction(), nothing happens that is noted outside the function.It’s not very clear what you’re trying to do … The point of constant data is, of course, that you’re not supposed to change it.