I was learning the basics of C programming , and I wanted to test some lines for strings.
This is my code:
int main(){ char a[] = "abc"; strcpy(a,"pqrst"); printf("%s; %d",a, sizeof(a)); } I expected the code to output size=6 (p, q, r, s, t and '\0'), but instead, it still prints size=4. How does this work?
strcpy-call has a buffer-overrun (the source is two byte longer than the destination) => UB => everything's over.