1

I am trying to understand strcpy() function but I could not. As said in this page If destination string length is less than source string, entire source string value won’t be copied into destination string, Instead it will be truncated. But when I tried to run this program

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char my_full_name[]="TomCruse_MI";
    char my_school_name[]="DON_BOSCO";
    strcpy(my_school_name, my_full_name);
    printf("After strcpy() function to copy my name into my school : \'%s\'\n" , my_school_name);
    printf("\n");
    return 0;
}

I am getting the out as :

After strcpy() function to copy my name into my school : 'TomCruse_MI'

My question is how come the string 'TomCruse_MI' is not getting truncated even though the source string is larger than the destination size.

vicky
  • 2,119
  • 4
  • 18
  • 32

0 Answers0