在C語言中這是一種普遍的寫法,類似的有 num += 10 等價於 num = num + 10;可參見如下的程式:
#include<stdio.h>#include<stdlib.h>int main (){ int num = 20; num /= 10; printf("num = %d\n",num); //還原num的值 num = 20; num = num / 10; printf("num = %d\n",num); printf("\n"); //還原num的值 num = 20; num += 10; printf("num = %d\n",num); //還原num的值 num = 20; num = num + 10; printf("num = %d\n",num); return 0;}執行結果:num = 2num = 2num = 30num = 30
在C語言中 num /= 10 是一種簡便的寫法,其等價於 num = num / 10;
在C語言中這是一種普遍的寫法,類似的有 num += 10 等價於 num = num + 10;可參見如下的程式:
#include<stdio.h>#include<stdlib.h>int main (){ int num = 20; num /= 10; printf("num = %d\n",num); //還原num的值 num = 20; num = num / 10; printf("num = %d\n",num); printf("\n"); //還原num的值 num = 20; num += 10; printf("num = %d\n",num); //還原num的值 num = 20; num = num + 10; printf("num = %d\n",num); return 0;}執行結果:num = 2num = 2num = 30num = 30
可以看到兩次的運算結果是相同的。