101 地特四等計算機概論第39題 - 考試

By Regina
at 2013-06-29T10:30
at 2013-06-29T10:30
Table of Contents
這題簡單一點寫可以改成這樣...
void main()
{
if(1)
{
int y=1;
cout<<"first"<<endl;
if(0)
{
cout<<"second";
}
}
}
執行結果應該只有 first
簡單說跟while(1)的用法差不多
同樣的,改成
void main()
{
if(1)
{
int y=1;
cout<<"first"<<endl;
if(y=1-1)
{
cout<<"second";
}
}
}
結果會是一樣的,只有first
第七行 if(y=1-1)那邊,會先運算y=1-1,然後得到y,然後進行 if 判斷
所以如果是 if ( y = x<0 )的狀況,一樣先運算y=x<0,然後再根據y 進行判斷
於是先運算x<0 不成立,回傳0
把0 assign 給y, y值為零
if(y)就變成if (0) 不執行迴圈
然後下面那個else 根據{}符號是配第一個if運作
所以最後x-y的時候,x為8、y為0
x-y=8;
這題滿有趣的XD
※ 引述《myIDis7 (個字)》之銘言:
: 原本看不懂題目的 原來是8進位
: ※ 引述《duncanchiu (鄧肯)》之銘言:
: : [考題] 國考歷屆考題與考題觀念討論(書裡看到的選這個)請附上想法、出處
: : #include <stdio.h>
: : main(){
: : int x = 007, y = 010;
: : if ( ++x >= y-- ) { if (y = x < 0) x = y + 4; }
: x = 007 + 1 = 010 >= 010 = y 進入判斷式
: if ( y = x < 0 = false = 0 ) 跳出判斷式
: : else x = x + 3;
: : printf(“%d\n”,x – y );
: 因此 x-y = 010 - 000 = 010(8進位) 為10進位的8 也就是D
: : }
: : (A)0 (B)2 (C)4 (D)8
: : 這題有陷阱
: : x與y 是八進制嗎?..
: : 用八進制與十進制算都不是正確答案(D)
: : 更不可能是十六進制
: : 有高手可以請教幫忙釐清觀念嗎!?
: : 謝謝
: 沒看到原題 但如果都沒標明是考成這樣 題目8進位 答案10進位 也太誇張了
--
void main()
{
if(1)
{
int y=1;
cout<<"first"<<endl;
if(0)
{
cout<<"second";
}
}
}
執行結果應該只有 first
簡單說跟while(1)的用法差不多
同樣的,改成
void main()
{
if(1)
{
int y=1;
cout<<"first"<<endl;
if(y=1-1)
{
cout<<"second";
}
}
}
結果會是一樣的,只有first
第七行 if(y=1-1)那邊,會先運算y=1-1,然後得到y,然後進行 if 判斷
所以如果是 if ( y = x<0 )的狀況,一樣先運算y=x<0,然後再根據y 進行判斷
於是先運算x<0 不成立,回傳0
把0 assign 給y, y值為零
if(y)就變成if (0) 不執行迴圈
然後下面那個else 根據{}符號是配第一個if運作
所以最後x-y的時候,x為8、y為0
x-y=8;
這題滿有趣的XD
※ 引述《myIDis7 (個字)》之銘言:
: 原本看不懂題目的 原來是8進位
: ※ 引述《duncanchiu (鄧肯)》之銘言:
: : [考題] 國考歷屆考題與考題觀念討論(書裡看到的選這個)請附上想法、出處
: : #include <stdio.h>
: : main(){
: : int x = 007, y = 010;
: : if ( ++x >= y-- ) { if (y = x < 0) x = y + 4; }
: x = 007 + 1 = 010 >= 010 = y 進入判斷式
: if ( y = x < 0 = false = 0 ) 跳出判斷式
: : else x = x + 3;
: : printf(“%d\n”,x – y );
: 因此 x-y = 010 - 000 = 010(8進位) 為10進位的8 也就是D
: : }
: : (A)0 (B)2 (C)4 (D)8
: : 這題有陷阱
: : x與y 是八進制嗎?..
: : 用八進制與十進制算都不是正確答案(D)
: : 更不可能是十六進制
: : 有高手可以請教幫忙釐清觀念嗎!?
: : 謝謝
: 沒看到原題 但如果都沒標明是考成這樣 題目8進位 答案10進位 也太誇張了
--
Tags:
考試
All Comments

By Elizabeth
at 2013-06-30T08:28
at 2013-06-30T08:28
Related Posts
請問哪裡找得到最多的民法概要題目解答?

By Hazel
at 2013-06-29T10:07
at 2013-06-29T10:07
101 地特四等計算機概論第39題

By Skylar Davis
at 2013-06-29T10:06
at 2013-06-29T10:06
資料結構幾題

By Harry
at 2013-06-29T09:14
at 2013-06-29T09:14
中華郵政企業管理第30題試題疑義回覆

By Edwina
at 2013-06-29T05:10
at 2013-06-29T05:10
102四等退除役軍人轉任考試~行政法3題

By Kristin
at 2013-06-29T03:36
at 2013-06-29T03:36