I wrote a small test program to see how I can pass a pointer to a char array to a function. This is my code:
#include <stdio.h>
#include <string.h>
int scopy(char *org ){
printf("the value of org is %s" , org);
printf("\n");
}
int main(void)
{
char original[11];
strcpy(original , "helloworld");
scopy(original);
printf("the value of original now is %s" , original);
return 0;
}
My knowledge of pointers tells me that org is a pointer that is passed the memory address of original[0] , when I execute this program I observe a few things that has confused me and has caused me to doubt the facts I have learnt about pointers.
when I print org I get the complete word back . but according to the logic if pointers isnt this supposed to print out the memory address;
when I try printing out out[1] , out[2] , codepad tells me that the process has ended abnormally
My basic doubt in this question is what exactly is org doing , I understand it is a char pointer pointing to a memory address (which??) . Any help would be appreciated . I am very new to c programming .
Also when I try a while loop like
while(out[i] !='\0')
printf("%s",out[i]);
it does not terminate at the '\0' . the strcpy documentation states that the '\0' is copied to the char array.