R.Tanaka.Ichiro's Blog

主にC# な話題です

目次

Blog 利用状況

ニュース

インクリメント演算子を前後に置いたときの優先順位

http://msdn.microsoft.com/ja-jp/library/aa691323.aspx
7.2.1 演算子の優先順位と結合規則

先日、確認したいことがあって演算子の優先順位を調べていて見つけたんですけど、前置インクリメント演算子と後置インクリメント演算子では

後置インクリメント演算子の方が優先順位が高い

のね~

何か変なの、と思って調べてみたいんだけど、どうやって動作を確認すれば良いのか見当がつかない orz

ちなみに、「++i;」と書いた場合と「i++;」と書いた場合の動作の違いなら、以下のようにすれば簡単に検証できる。


var a = 0;
var b = 0;
Console.WriteLine(++a); // 1 と表示
Console.WriteLine(b++); // 0 と表示


前置演算と後置演算の優先順位の動作検証ってできるんだろうか?

で、ついでに言うと、この優先順位が生きる時って、どんな時なんだろう?

まー、記述されている内容を見る限りだと、後置インクリメント(デクリメント)演算子は、基本式だからという理由らしいけど・・・

投稿日時 : 2009年6月8日 15:02

Feedback

# re: インクリメント演算子を前後に置いたときの優先順位 2009/06/08 15:14 aetos

個人的には前置しか使いません。
かつ、for の場合を除いて、単独で文となるように使います。

# re: インクリメント演算子を前後に置いたときの優先順位 2009/06/08 15:36 K5

私も前置しか使わないな~
基本的には前置のほうが処理早い&意味合いに動作が近いし。

aetosさんと同じく単独でしか使わないようにしてます。
目的としては前置と後置を書き換えても動作が変わらないようにって感じですが。
#以前規約がどうとかで勝手に書き換えられてバグになったことがあるので…つーか違いぐらい理解しとけよorz

# re: インクリメント演算子を前後に置いたときの優先順位 2009/06/08 17:03 biac

ぬぅぅ… 難し~ orz

--i++;
って書くと、 コンパイラさまは↓こう怒ってくるですよ。
http://msdn.microsoft.com/ja-jp/library/bb310865.aspx
/*
コンパイラ エラー CS1059
インクリメント演算子またはデクリメント演算子のオペランドには、変数、プロパティ、またはインデクサを指定してください。
*/
これはすなわち、
--(i++);
と解釈したので、 -- のオペランドが式になっちゃった、 ってことで、 つまり後置インクリメントが優先されてる …で、 ダメっすか? f(^^;

# re: インクリメント演算子を前後に置いたときの優先順位 2009/06/08 18:32 Jitta

biac先生!
(--i)++; との違いは?

# re: インクリメント演算子を前後に置いたときの優先順位 2009/06/08 18:48 biac

> (--i)++; との違いは?

が~ん… orz
おんなじ怒られ方をするよぉ~ (;;)

ってことで、 撤回。 検証のやり方が、 私にはわかんねーっす f(^^;

int f() { return 1; }
void test() {
 --f();
 f()++;
}
とか書いても、 同じ怒られ方するし~ orz
# C# コンパイラ、エラーメッセージの手抜きだ! (w

# re: インクリメント演算子を前後に置いたときの優先順位 2009/06/08 21:15 刈歩 菜良 CTP

正解は<del>越後製菓</del>
インクリメント/デクリメント演算子を式とかに混ぜて使っちゃだめ~~~ です。
シャノンさんがいうように、単独式でしか使いません。

その場合、前置も後置も関係ないのでどちらでもOKかと。

可読性第一です。


ちなみに、前置後置で違いがあることすら教えません。
# C++経験者がまれにいて質問を受けることもありますが、その場合も単独で使うように説明します。

# re: インクリメント演算子を前後に置いたときの優先順位 2009/06/09 11:51 aetos

なんか違和感がある。

int i = ++x; の場合、++x の式の値は x + 1 です。
int i = x++; の場合、x++ の式の値は x です?

C# の言語仕様では、代入 = の優先順位は最低です。
なので、前置の場合は、まず優先順位の高い ++x が行われ、続いて = が行われます。
後置の場合は? なんだか i = x が先に行われ、後で x++ が行われているようにも見えます。

式の値の決定のタイミングを考えると、前置でも後置でも = より先です。
前置は言うに及ばず、後置は、式の値を x と決定してから代入が行われています。加算は代入の前でも後でも構いません(既に式の値は決定しているので、代入の結果は変化しません)。

うーん? 関係あるようなないような?

# インクリメント演算子を前後に置いたときの優先順位(その2) 2009/06/09 14:06 R.Tanaka.Ichiro's Blog

インクリメント演算子を前後に置いたときの優先順位(その2)

# インクリメント演算子を前後に置いたときの優先順位(その2) 2009/06/09 14:08 R.Tanaka.Ichiro's Blog

インクリメント演算子を前後に置いたときの優先順位(その2)

# Hi there, the whole thing is going well here and ofcourse every one is sharing information, that's actually excellent, keep up writing. 2019/05/06 16:59 Hi there, the whole thing is going well here and o

Hi there, the whole thing is going well here and ofcourse every one is sharing information, that's
actually excellent, keep up writing.

# Hey there! Someone in my Myspace group shared this website with us so I came to check it out. I'm definitely loving the information. I'm bookmarking and will be tweeting this to my followers! Fantastic blog and fantastic design and style. 2019/05/08 16:22 Hey there! Someone in my Myspace group shared this

Hey there! Someone in my Myspace group shared
this website with us so I came to check it out.
I'm definitely loving the information. I'm bookmarking and will be tweeting this
to my followers! Fantastic blog and fantastic design and style.

# Hi, i think that i saw you visited my blog thus i came to “return the favor”.I'm trying to find things to improve my site!I suppose its ok to use a few of your ideas!! 2019/05/11 16:34 Hi, i think that i saw you visited my blog thus i

Hi, i think that i saw you visited my blog thus i came
to “return the favor”.I'm trying to find things to improve my site!I suppose its ok to use a
few of your ideas!!

# Hi there, I would like to subscribe for this weblog to obtain newest updates, so where can i do it please help. 2019/05/30 11:23 Hi there, I would like to subscribe for this weblo

Hi there, I would like to subscribe for this weblog to obtain newest updates, so where can i do it please help.

# Hi, i think that i saw you visited my web site so i came to “return the favor”.I am attempting to find things to improve my site!I suppose its ok to use a few of your ideas!! 2019/06/02 2:10 Hi, i think that i saw you visited my web site so

Hi, i think that i saw you visited my web site so i came to
“return the favor”.I am attempting to find things to improve my
site!I suppose its ok to use a few of your ideas!!

# After looking into a handful of the articles on your website, I honestly like your way of blogging. I bookmarked it to my bookmark webpage list and will be checking back in the near future. Please visit my web site as well and let me know how you feel. 2019/06/08 2:09 After looking into a handful of the articles on yo

After looking into a handful of the articles on your website, I honestly like your way of blogging.
I bookmarked it to my bookmark webpage list and will be
checking back in the near future. Please visit
my web site as well and let me know how you feel.

# Good day I am so happy I found your website, I really found you by error, while I was looking on Digg for something else, Regardless I am here now and would just like to say kudos for a marvelous post and a all round enjoyable blog (I also love the them 2019/09/16 20:14 Good day I am so happy I found your website, I rea

Good day I am so happy I found your website, I really found you by error, while I was looking on Digg for something
else, Regardless I am here now and would just like to say
kudos for a marvelous post and a all round enjoyable blog (I
also love the theme/design), I don’t have time to
go through it all at the moment but I have bookmarked
it and also added in your RSS feeds, so when I have time I will be back
to read more, Please do keep up the superb jo.

# doxycycline https://doxycyline1st.com/
buy doxycycline hyclate 100mg without a rx 2022/02/26 0:34 Jusidkid

doxycycline https://doxycyline1st.com/
buy doxycycline hyclate 100mg without a rx

# doxycycline generic https://doxycyline1st.com/
doxycycline 150 mg 2022/02/26 9:38 Jusidkid

doxycycline generic https://doxycyline1st.com/
doxycycline 150 mg

# clomid without prescription http://clomidfast.site/ 2022/04/12 12:52 Clomids

clomid without prescription http://clomidfast.site/

# YYPKIHAQrzOq 2022/04/19 10:34 johnansaz

http://imrdsoacha.gov.co/silvitra-120mg-qrms

# clomid generic name https://clomidonline.icu/ 2022/07/08 13:33 Clomidj

clomid generic name https://clomidonline.icu/

# Bystolic https://allpharm.store/ 2022/07/21 22:01 AllPharm

Bystolic https://allpharm.store/

# buy metformin uk https://glucophage.top/
metformin order canada 2022/08/23 7:49 Niujsdkj

buy metformin uk https://glucophage.top/
metformin order canada

# pills for erection https://ed-pills.xyz/
ed pills otc 2022/09/15 19:09 EdPills

pills for erection https://ed-pills.xyz/
ed pills otc

# doxycycline 150 mg https://buydoxycycline.icu/ 2022/10/08 11:53 Doxycycline

doxycycline 150 mg https://buydoxycycline.icu/

#  https://clomidforsale.site/ 2022/11/13 14:21 ForSale

https://clomidforsale.site/

# india buy prednisone online https://prednisonepills.site/
how much is prednisone 5mg 2022/11/30 0:51 Prednisone

india buy prednisone online https://prednisonepills.site/
how much is prednisone 5mg

# le migliori pillole per l'erezione https://viasenzaricetta.com/# 2023/04/16 13:26 ViaSenza

le migliori pillole per l'erezione https://viasenzaricetta.com/#

# buy generic doxycycline - https://doxycyclinesale.pro/# 2023/04/21 17:34 Doxycycline

buy generic doxycycline - https://doxycyclinesale.pro/#

# prednisone 10mg cost - https://prednisonesale.pro/# 2023/04/22 4:51 Prednisone

prednisone 10mg cost - https://prednisonesale.pro/#

# buy cytotec in usa - https://cytotecsale.pro/# 2023/04/29 5:05 Cytotec

buy cytotec in usa - https://cytotecsale.pro/#

# nystatin cream over the counter https://overthecounter.pro/# 2023/05/08 23:13 OtcJikoliuj

nystatin cream over the counter https://overthecounter.pro/#

# legitimate canadian internet pharmacies https://pillswithoutprescription.pro/# 2023/05/15 4:00 PillsPresc

legitimate canadian internet pharmacies https://pillswithoutprescription.pro/#

# erection pills that work: https://edpills.pro/# 2023/05/15 15:36 EdPillsPro

erection pills that work: https://edpills.pro/#

# legitimate online canadian pharmacies https://pillswithoutprescription.pro/# 2023/05/16 10:01 PillsPro

legitimate online canadian pharmacies https://pillswithoutprescription.pro/#

# otc ed pills https://edpill.pro/# - ed medication online 2023/06/27 14:54 EdPills

otc ed pills https://edpill.pro/# - ed medication online

# Paxlovid over the counter https://paxlovid.pro/# - paxlovid price 2023/07/02 17:31 Paxlovid

Paxlovid over the counter https://paxlovid.pro/# - paxlovid price

# paxlovid cost without insurance https://paxlovid.store/
paxlovid for sale 2023/07/13 13:23 Paxlovid

paxlovid cost without insurance https://paxlovid.store/
paxlovid for sale

# ed medications online https://edpills.ink/# - natural ed remedies 2023/07/27 1:14 EdPills

ed medications online https://edpills.ink/# - natural ed remedies

# singles dating site 2023/08/09 19:09 WayneGurry

dating single: http://datingtopreview.com/# - datinghotlot

# reputable indian pharmacies 2023/08/22 3:31 Jeffreybloft

http://gabapentin.pro/# buy gabapentin online

# п»їpaxlovid 2023/08/23 22:39 Davidvat

https://ed-pills.men/# erectile dysfunction pills

# farmacie online autorizzate elenco 2023/09/25 1:04 Archieonelf

https://pharmacieenligne.icu/# Pharmacie en ligne livraison 24h

# acquisto farmaci con ricetta 2023/09/26 2:25 Archieonelf

http://farmaciaonline.men/# farmacia online miglior prezzo

# online apotheke deutschland 2023/09/26 13:40 Williamreomo

http://onlineapotheke.tech/# versandapotheke versandkostenfrei
versandapotheke

# internet apotheke 2023/09/26 15:40 Williamreomo

http://onlineapotheke.tech/# online apotheke gГ?nstig
internet apotheke

# п»їonline apotheke 2023/09/26 23:11 Williamreomo

http://onlineapotheke.tech/# online apotheke deutschland
online apotheke gГ?nstig

# online apotheke gГјnstig 2023/09/27 1:00 Williamreomo

http://onlineapotheke.tech/# online apotheke preisvergleich
online apotheke preisvergleich

# farmacia online piГ№ conveniente 2023/09/27 2:45 Archieonelf

http://farmaciaonline.men/# farmacie online sicure

# versandapotheke deutschland 2023/09/27 3:26 Williamreomo

https://onlineapotheke.tech/# online apotheke versandkostenfrei
online apotheke gГ?nstig

# п»їonline apotheke 2023/09/27 3:55 Williamreomo

https://onlineapotheke.tech/# online apotheke versandkostenfrei
versandapotheke

# gГјnstige online apotheke 2023/09/27 5:12 Williamreomo

http://onlineapotheke.tech/# п»?online apotheke
gГ?nstige online apotheke

# п»їonline apotheke 2023/09/27 6:51 Williamreomo

http://onlineapotheke.tech/# п»?online apotheke
online apotheke preisvergleich

# п»їonline apotheke 2023/09/27 7:47 Williamreomo

https://onlineapotheke.tech/# online apotheke versandkostenfrei
gГ?nstige online apotheke

# п»їonline apotheke 2023/09/27 8:56 Williamreomo

http://onlineapotheke.tech/# online apotheke preisvergleich
gГ?nstige online apotheke

# comprare farmaci online con ricetta 2023/09/27 17:38 Rickeyrof

acheter sildenafil 100mg sans ordonnance

# farmacia online senza ricetta 2023/09/27 19:46 Rickeyrof

acheter sildenafil 100mg sans ordonnance

# canada drug stores 2023/10/16 1:45 Kiethamert

http://gabapentin.world/# gabapentin 600 mg

# canada pharm 2023/10/16 13:37 Dannyhealm

They source globally to provide the best care locally. https://mexicanpharmonline.shop/# mexican pharmaceuticals online

# canadian pills online 2023/10/16 22:31 Dannyhealm

Actual trends of drug. https://mexicanpharmonline.com/# mexican mail order pharmacies

# mail order pharmacies canada 2023/10/17 2:34 Dannyhealm

Efficient, effective, and always eager to assist. http://mexicanpharmonline.com/# mexico drug stores pharmacies

# online-rx 2023/10/17 21:36 Dannyhealm

The children's section is well-stocked with quality products. https://mexicanpharmonline.com/# reputable mexican pharmacies online

# pharmacies in canada online 2023/10/17 23:19 Dannyhealm

Their international patient care is impeccable. http://mexicanpharmonline.com/# mexican mail order pharmacies

# paxlovid india https://paxlovid.bid/ paxlovid india 2023/10/25 23:19 Paxlovid

paxlovid india https://paxlovid.bid/ paxlovid india

# paxlovid covid 2023/10/26 19:42 LarryNef

http://stromectol.icu/# ivermectin buy nz

# cure ed 2023/11/23 12:02 WilliamApomb

https://tadalafil.trade/# tadalafil generic otc

# doxycycline medication https://doxycycline.forum/ order doxycycline online 2023/11/25 13:32 Doxycycline

doxycycline medication https://doxycycline.forum/ order doxycycline online

# canadian pharmacies no prescription needed 2023/11/30 12:33 MichaelBum

https://paxlovid.club/# paxlovid generic

# paxlovid buy 2023/12/01 2:11 Mathewhip

paxlovid pill http://paxlovid.club/# paxlovid

# farmacie on line spedizione gratuita https://farmaciait.pro/ farmacie online autorizzate elenco 2023/12/04 10:26 Farmacia

farmacie on line spedizione gratuita https://farmaciait.pro/ farmacie online autorizzate elenco

# farmacias online baratas 2023/12/07 15:39 RonnieCag

http://vardenafilo.icu/# farmacia envíos internacionales

# farmacia barata 2023/12/07 18:45 RonnieCag

http://sildenafilo.store/# se puede comprar sildenafil sin receta

# farmacia online madrid 2023/12/07 21:59 RonnieCag

https://vardenafilo.icu/# farmacias online seguras

# ï»¿farmacia online 2023/12/08 1:07 RonnieCag

https://tadalafilo.pro/# farmacia online barata

# farmacias online seguras en españa 2023/12/08 4:14 RonnieCag

http://farmacia.best/# farmacia online madrid

# farmacias online seguras en españa 2023/12/08 21:51 RonnieCag

http://tadalafilo.pro/# farmacia online barata

# farmacia envíos internacionales 2023/12/09 19:42 RonnieCag

http://vardenafilo.icu/# farmacia envíos internacionales

# farmacia online envío gratis 2023/12/10 2:21 RonnieCag

https://tadalafilo.pro/# farmacias online seguras en españa

# ï»¿farmacia online 2023/12/10 6:21 RonnieCag

http://vardenafilo.icu/# farmacias baratas online envío gratis

# ï»¿farmacia online 2023/12/10 9:30 RonnieCag

https://vardenafilo.icu/# farmacia envíos internacionales

# farmacia online 24 horas 2023/12/10 12:23 RonnieCag

https://tadalafilo.pro/# farmacias baratas online envío gratis

# farmacia 24h 2023/12/10 15:27 RonnieCag

https://vardenafilo.icu/# farmacia online envío gratis

# farmacia envíos internacionales 2023/12/11 2:32 RonnieCag

http://vardenafilo.icu/# farmacia 24h

# ï»¿farmacia online 2023/12/11 21:11 RonnieCag

http://tadalafilo.pro/# farmacia online madrid

# ï»¿pharmacie en ligne 2023/12/14 7:12 Larryedump

https://pharmacieenligne.guru/# Pharmacie en ligne livraison gratuite

# ed medication https://edpills.tech/# otc ed pills 2023/12/23 8:29 EdPills

ed medication https://edpills.tech/# otc ed pills

# buying clomid without rx 2023/12/26 23:03 RaymondGrido

https://clomid.site/# where to buy cheap clomid

# how to get generic clomid pills 2023/12/30 0:22 RaymondGrido

https://paxlovid.win/# paxlovid buy

# can i buy cheap clomid tablets 2024/01/12 13:20 JeffreyRom

https://prednisone.auction/# prednisone 40 mg rx

# zestril 30mg generic 2024/01/13 21:07 CharlieThecy

https://misoprostol.shop/# Misoprostol 200 mg buy online

# tamoxifen hormone therapy 2024/01/20 15:01 Normantug

https://clomidpharm.shop/# order clomid price

# buy generic clomid prices 2024/01/20 16:23 LarryVoP

Excellent consultation with clear communication https://clomidpharm.shop/# get generic clomid pills

# no prescription canadian pharmacies 2024/01/23 17:07 Stevenhex

http://edpills.bid/# natural remedies for ed

# ivermectin price 2024/01/30 9:45 Andrewamabs

https://prednisonetablets.shop/# prednisone cost canada

# ivermectin 0.1 2024/01/30 17:55 Andrewamabs

http://prednisonetablets.shop/# prednisone for sale online

# ivermectin generic cream 2024/01/31 2:18 Andrewamabs

http://prednisonetablets.shop/# 5 mg prednisone daily

# amoxil generic 2024/02/01 4:54 JamesBUT

https://ivermectin.store/# ivermectin 4000

# buying from canadian pharmacies 2024/02/02 11:56 PatrickGudge

https://canadianpharm.store/# canadian drug prices canadianpharm.store

# zestril 40 mg 2024/02/25 19:37 Charlesmax

https://stromectol.fun/# stromectol uk buy

# christian dating for free 2024/03/03 14:33 Thomasjax

https://lanarhoades.fun/# lana rhoades izle

# meet girls for free 2024/03/03 17:10 RodrigoGrany

https://sweetiefox.online/# sweeti fox

# dating wites 2024/03/04 5:45 RodrigoGrany

https://sweetiefox.online/# Sweetie Fox izle

# dating sites our time 2024/03/04 15:27 Thomasjax

http://angelawhite.pro/# Angela White

# hot dating match 2024/03/07 9:20 HowardBox

completely free dating sites: http://miamalkova.life/# mia malkova videos

# totally free dating service 2024/03/08 3:25 HowardBox

asien dating online: http://sweetiefox.pro/# sweetie fox video

# site de apostas 2024/03/11 13:45 Robertcog

http://aviatormocambique.site/# aviator online

# melhor jogo de aposta 2024/03/14 9:19 BrianTop

http://jogodeaposta.fun/# aplicativo de aposta

# ganhar dinheiro jogando 2024/03/14 20:30 BrianTop

https://aviatorghana.pro/# aviator game

# mexican border pharmacies shipping to usa 2024/03/17 3:32 ManuelMap

https://indianpharm24.com/# indian pharmacies safe indianpharm.store

# gates of olympus demo oyna 2024/03/30 3:48 KeithNaf

http://gatesofolympus.auction/# gates of olympus giris

# can you buy generic clomid pills 2024/04/03 2:40 Robertsuela

https://clomidall.shop/# can i order clomid pills

# can you get cheap clomid without rx 2024/04/03 21:31 Robertsuela

https://prednisoneall.com/# prednisone steroids

# generic clomid without rx 2024/04/04 2:18 Robertsuela

http://amoxilall.shop/# amoxil generic

# cost of clomid 2024/04/04 11:08 Robertsuela

http://clomidall.shop/# get cheap clomid price

# can i buy clomid prices 2024/04/04 23:59 Robertsuela

https://prednisoneall.com/# order prednisone from canada

# how can i get cheap clomid 2024/04/05 13:50 Robertsuela

https://prednisoneall.shop/# prednisone 20 mg in india

# doxycycline hyc 100mg 2024/04/14 5:56 Archiewef

http://misoprostol.top/# buy cytotec online

# diflucan.com 2024/04/15 9:04 Josephfep

https://prednisonea.store/# prednisone 10mg

# order prescription from canada 2024/04/17 7:44 ArmandoWem

https://edpill.top/# online erectile dysfunction pills

タイトル
名前
Url
コメント