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

Reply
 
Thread Tools

C/C++ prioroty question
Old 11.08.2004, 10:01   #1
★★★★★★★★★★★★★
 
Hrach_Techie's Avatar
 
Join Date: 08 2004
Location: London, UK
Age: 45
Posts: 16,531
Rep Power: 7
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?

Old 11.08.2004, 10:25   #2
Ребе - коп!
 
Speedy Gonzales's Avatar
 
Join Date: 03 2003
Location: sfba
Age: 47
Posts: 4,189
Rep Power: 5
Default

Операторы ++ и * имеют одинаковый приоритет и порядок выполнения справа налево. Скобки тебе не помогут?

Old 11.08.2004, 10:47   #3
Уже давно не младенец
 
Join Date: 09 2002
Location: Yerevan, Armenia
Posts: 83
Rep Power: 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...

Old 11.08.2004, 11:03   #4
Грустно...
 
Agregat's Avatar
 
Join Date: 08 2002
Location: Там, где всегда идут дожди
Age: 42
Posts: 21,717
Rep Power: 9
Default

operator ++(void) has to be applied to something. Something is dereferenced m.

Old 11.08.2004, 12:49   #5
the mochinger
 
Hans Andersen's Avatar
 
Join Date: 02 2002
Location: Paranoid Android, @10:50
Age: 44
Posts: 1,894
Rep Power: 5
Default

just curious, what were you expecting?

Old 11.08.2004, 13:15   #6
Ребе - коп!
 
Speedy Gonzales's Avatar
 
Join Date: 03 2003
Location: sfba
Age: 47
Posts: 4,189
Rep Power: 5
Default

guess he expects 5

Old 11.08.2004, 13:39   #7
the mochinger
 
Hans Andersen's Avatar
 
Join Date: 02 2002
Location: Paranoid Android, @10:50
Age: 44
Posts: 1,894
Rep Power: 5
Default

but how can one ++arrays?

Old 11.08.2004, 19:09   #8
Грустно...
 
Agregat's Avatar
 
Join Date: 08 2002
Location: Там, где всегда идут дожди
Age: 42
Posts: 21,717
Rep Power: 9
Default

никак на самом деле.

վոշմի վեռնագիր
Old 12.08.2004, 10:55   #9
Պապայություն !
 
Join Date: 08 2004
Location: Yerevan, Armenia
Age: 45
Posts: 1
Rep Power: 0
Wink վոշմի վեռնագիր

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




Реклама:
реклама

All times are GMT. The time now is 20:39.
Top

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