Armenian Knowledge Base  

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

Reply
 
LinkBack Thread Tools
Old 11.08.2004, 11:01   #1
★★★★★★★★★★★★★
 
Hrach_Techie's Avatar
 
Join Date: 08 2004
Location: London, UK
Age: 38
Posts: 16,531
Downloads: 8
Uploads: 0
Reputation: 482 | 6
Default C/C++ prioroty question

Am confused..

int m[2] = { 1, 5 };

cout << ++*m; //this gives 2

my question is, why is the dereference operator evaluated before ++ inspite of the fact that ++ has a higher precedence than *?

ANy pointers there?
Reply With Quote
Old 11.08.2004, 11:25   #2
Ребе - коп!
 
Speedy Gonzales's Avatar
 
Join Date: 03 2003
Location: sfba
Age: 40
Posts: 4,188
Downloads: 0
Uploads: 0
Reputation: 29 | 3
Default

Операторы ++ и * имеют одинаковый приоритет и порядок выполнения справа налево. Скобки тебе не помогут?
Reply With Quote
Old 11.08.2004, 11:47   #3
Уже давно не младенец
 
Join Date: 09 2002
Location: Yerevan, Armenia
Posts: 83
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default

Everything seems to be fine... I don't see any problem here.
To be simple... in case of prefix unary operators, the operators are executed in the right-to-left order...
Reply With Quote
Old 11.08.2004, 12:03   #4
Грустно...
 
Agregat's Avatar
 
Join Date: 08 2002
Location: Там, где всегда идут дожди
Age: 35
Posts: 21,717
Downloads: 2
Uploads: 0
Reputation: 250 | 7
Default

operator ++(void) has to be applied to something. Something is dereferenced m.
Reply With Quote
Old 11.08.2004, 13:49   #5
the mochinger
 
Hans Andersen's Avatar
 
Join Date: 02 2002
Location: Paranoid Android, @10:50
Age: 38
Posts: 1,894
Downloads: 2
Uploads: 0
Reputation: 204 | 4
Default

just curious, what were you expecting?
Reply With Quote
Old 11.08.2004, 14:15   #6
Ребе - коп!
 
Speedy Gonzales's Avatar
 
Join Date: 03 2003
Location: sfba
Age: 40
Posts: 4,188
Downloads: 0
Uploads: 0
Reputation: 29 | 3
Default

guess he expects 5
Reply With Quote
Old 11.08.2004, 14:39   #7
the mochinger
 
Hans Andersen's Avatar
 
Join Date: 02 2002
Location: Paranoid Android, @10:50
Age: 38
Posts: 1,894
Downloads: 2
Uploads: 0
Reputation: 204 | 4
Default

but how can one ++arrays?
Reply With Quote
Old 11.08.2004, 20:09   #8
Грустно...
 
Agregat's Avatar
 
Join Date: 08 2002
Location: Там, где всегда идут дожди
Age: 35
Posts: 21,717
Downloads: 2
Uploads: 0
Reputation: 250 | 7
Default

никак на самом деле.
Reply With Quote
Old 12.08.2004, 11:55   #9
Պապայություն !
 
Join Date: 08 2004
Location: Yerevan, Armenia
Age: 39
Posts: 1
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Wink վոշմի վեռնագիր

[removed by administrator: you have one warning, read forum rules and behave correspondingly]
Reply With Quote
Sponsored Links
Reply

« - | stdout redirection »
Thread Tools


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

All times are GMT. The time now is 12:17.


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