1. 程式人生 > >一個奇怪的記憶體賦值

一個奇怪的記憶體賦值

還沒理解這其中的奧祕,有知道說下

#include <stdio.h>
#include <string.h>
int main()
{
    char str_t[]="This String comes from t";//初始化字元陣列
    char str_s[]="This is an empty s";//初始化字元陣列
    printf("%s %ld\n%s %ld\n",str_t, strlen(str_t), str_s, strlen(str_s));
    char *t=str_t;//初始化字元指標
    char *s=str_s;//初始化字元指標
while(*s++=*t++);//*的優先順序比++高,且為右結合,因此會將t的值逐個賦值給s,直到結果為'\0' printf("%s %ld\n%s %ld\n",str_t, strlen(str_t), str_s, strlen(str_s)); return 0; }
[email protected]:# ./xx
This String comes from t 24
This is an empty s 18
This String comes from t 24
This String comes from t 24

看到沒,字元陣列的空間被擴充套件了,但是沒有進行過記憶體申請。。。