Dear all,
Today I am dealing with a code. Looks like similar method and the way but when I run the code output is:
[abcde] [5] [6]
[abcde] [5] [8]
What is the rule for indexing and referencing in pointer arithmetics. ptr1 and ptr2 64 bit reference to a char array. I am a little confused. Are there any idea for making this issue clear. I would be much appreciated.
Code:
#include<studio.h>
#include<stdlib.h>
#include<string.h>
int main(){
    char ptr1[]="abcde";
    char *ptr2=malloc(sizeof(char)*6);
    strcpy(ptr2,ptr1);
    printf("[%s] [%ld] [%ld]\n",ptr1,strlen(ptr1),sizeof(ptr1);
    printf("[%s] [%ld] [%ld]\n",ptr2,strlen(ptr2),sizeof(ptr2);
    getchar();
    return (0);
}