-------------------------------------------------------------------
經典問題2:c/c++ 程序設計 ---i++問題
-------------------------------------------------------------------
1)面試題:What will be the output of the following C code?
1 #include <stdio.h>
2
3 int main()
4 {
5 int b = 3;
6 int arr[] = {6,7,8,9,10};
7 int *ptr = arr;
8 *(ptr++) += 123;
9 printf("%d,%d/n ",*ptr,*(++ptr));
10 return 0;
11 }
------------------------------------
result:
在函數‘main’中:
9: 警告: ‘ptr’上的運算結果可能是未定義的
5: 警告: 未使用的變量‘b’
----------
$ ./a.out
8,8
------------------------------------
知識點:printf();語句是從右往左運算;
經典問題2:c/c++ 程序設計 ---i++問題
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.