Armenian Knowledge Base  

Go Back   Armenian Knowledge Base > Technical sections > Languages, Compilers, Interpreters > C/C++
Register

Reply
 
LinkBack Thread Tools
Old 22.04.2005, 18:40   #1
Профессор
 
Nikita's Avatar
 
Join Date: 01 2005
Location: Perm
Age: 38
Posts: 2,142
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Wink задачка для ассов c/c++

с виду тривиальная задачка ...

#include <stdio.h>
int main (int argc, unsigned char **argv) {
int i = 0;
i = i++;
printf ("i = %d\n", i);
return 0;
}

какое значение i будет выведенно ?
Reply With Quote
Old 22.04.2005, 18:44   #2
Banned
 
DaNYer's Avatar
 
Join Date: 10 2002
Location: Brooklyn, New York
Age: 39
Posts: 3,760
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default

i=i++ eto kaneshna kruto
Reply With Quote
Old 22.04.2005, 18:47   #3
»
 
z0mbie's Avatar
 
Join Date: 01 2002
Posts: 777
Downloads: 1
Uploads: 0
Reputation: 0 | 0
Default

0
Reply With Quote
Old 22.04.2005, 18:49   #4
Banned
 
DaNYer's Avatar
 
Join Date: 10 2002
Location: Brooklyn, New York
Age: 39
Posts: 3,760
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default

rezul'tat i++ vozvrashaet 0. znachit tipa vse v poryadke. a potom etot rezul'tat pripisivaetsya k i. znachit budet 0
Reply With Quote
Old 22.04.2005, 18:52   #5
Banned
 
DaNYer's Avatar
 
Join Date: 10 2002
Location: Brooklyn, New York
Age: 39
Posts: 3,760
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default

poprobui eshe i=printf("%d", i); ili eshe chego.
Reply With Quote
Old 22.04.2005, 18:57   #6
»
 
z0mbie's Avatar
 
Join Date: 01 2002
Posts: 777
Downloads: 1
Uploads: 0
Reputation: 0 | 0
Default

btw ас пишется с одним с :]
Attached Thumbnails
1016.jpg  
Reply With Quote
Old 22.04.2005, 18:59   #7
Профессор
 
Nikita's Avatar
 
Join Date: 01 2005
Location: Perm
Age: 38
Posts: 2,142
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default

а можете обьяснить почему ?
Reply With Quote
Old 22.04.2005, 19:05   #8
Banned
 
DaNYer's Avatar
 
Join Date: 10 2002
Location: Brooklyn, New York
Age: 39
Posts: 3,760
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default

ya vrode obyasnil. rezul'tat operacii i++ vozvrashaet 0
Reply With Quote
Old 22.04.2005, 19:05   #9
»
 
z0mbie's Avatar
 
Join Date: 01 2002
Posts: 777
Downloads: 1
Uploads: 0
Reputation: 0 | 0
Default

потому что приоритет унарного оператора выше чем оператора присвоения
Reply With Quote
Old 22.04.2005, 19:06   #10
Профессор
 
Nikita's Avatar
 
Join Date: 01 2005
Location: Perm
Age: 38
Posts: 2,142
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default

не обьяснил
Reply With Quote
Old 22.04.2005, 19:14   #11
Banned
 
DaNYer's Avatar
 
Join Date: 10 2002
Location: Brooklyn, New York
Age: 39
Posts: 3,760
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default

imeyushie glaza da uvidyat...
Reply With Quote
Old 22.04.2005, 19:15   #12
Профессор
 
Nikita's Avatar
 
Join Date: 01 2005
Location: Perm
Age: 38
Posts: 2,142
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default

Danyer
пойми меня правильно
я имею ввиду по стандарту
а не логикой ... твоей логикой
Reply With Quote
Old 22.04.2005, 19:21   #13
Banned
 
DaNYer's Avatar
 
Join Date: 10 2002
Location: Brooklyn, New York
Age: 39
Posts: 3,760
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default

oi, sorry ya ne zametil, dlya accov...

acc eto je latinica... sorry. molchu.

xotya zombie toje neslabo skazal
Reply With Quote
Old 22.04.2005, 19:23   #14
ЙЦУКЕН
 
Join Date: 07 2002
Location: 0x68,0x69,0x72, 0x69,0x6e,0x67, 0x20,0x6e,0x6f, 0x77
Age: 47
Posts: 3,118
Downloads: 0
Uploads: 0
Reputation: 5 | 0
Default

Quote:
Originally Posted by z0mbie
btw ас пишется с одним с :]
на русском на других языках это может быть не так.
ну извини, какой есть так и формулирует.

а вообще-то постфиксный оператор инкремента(декремента) выполняется _после_ выполнения _всей_ операции в которой он записан.

посему имеем --
i=i;
i++;
что и наблюдаем на экране при выполнении
Reply With Quote
Old 22.04.2005, 19:29   #15
Профессор
 
Nikita's Avatar
 
Join Date: 01 2005
Location: Perm
Age: 38
Posts: 2,142
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default

я часто делаю ошибки
ну и что ?
Кстате читай беспредел ... там для тебя сообщение ...
Reply With Quote
Sponsored Links
Reply

Thread Tools


На правах рекламы:
реклама

All times are GMT. The time now is 11:46.


Powered by vBulletin® Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.