﻿
{"id":6262,"date":"2017-05-15T09:51:39","date_gmt":"2017-05-15T09:51:39","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=6262"},"modified":"2017-05-15T09:51:39","modified_gmt":"2017-05-15T09:51:39","slug":"cta-gostericipointer-gostericilerde-aritmatik-islemler-vi","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/cta-gostericipointer-gostericilerde-aritmatik-islemler-vi\/","title":{"rendered":"C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6stericilerde Aritmatik \u0130\u015flemler \u2013 VI"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>\u00d6nceki <a href=\"http:\/\/www.gencayyildiz.com\/blog\/cta-gostericipointer-gostericiler-arasinda-tur-donusumleri-v\/\" target=\"_blank\" rel=\"noopener noreferrer\">C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6stericiler Aras\u0131nda T\u00fcr D\u00f6n\u00fc\u015f\u00fcmleri \u2013 V<\/a> ba\u015fl\u0131kl\u0131 makalemizde g\u00f6stericilerde t\u00fcr d\u00f6n\u00fc\u015f\u00fcmlerini ele alm\u0131\u015ft\u0131k. \u015eimdi ise g\u00f6stericiler \u00fczerinde aritmatik i\u015flemleri de\u011ferlendiriyor olaca\u011f\u0131z.<\/p>\n<h4>G\u00f6stericiler \u0130le Sabit Tamsay\u0131 De\u011ferlerini Toplama\/\u00c7\u0131karma<\/h4>\n<p>G\u00f6stericiler \u00fczerinde sabit tamsay\u0131 de\u011ferler ile ekleme ve \u00e7\u0131karma gibi aritmatik i\u015flemler ger\u00e7ekle\u015ftirebiliriz. Ancak bu g\u00f6stericilerde yap\u0131lan bu i\u015flemler normal de\u011fi\u015fkenlere nazaran biraz farkl\u0131 i\u015flevsellik g\u00f6stermektedir. G\u00f6stericiye sabit bir tamsay\u0131sal de\u011ferin eklenmesi yahut \u00e7\u0131kar\u0131lmas\u0131 g\u00f6stericinin adres bile\u015fenini g\u00f6stericinin t\u00fcr\u00fcn\u00fcn byte de\u011feri kadar artt\u0131rmak yahut azaltmak mahiyetine gelmektedir. Yani demek istedi\u011fim o ki; g\u00f6stericiler \u00fczerinde yap\u0131lan aritmatik i\u015flemler, g\u00f6stericinin de\u011ferinde de\u011fil g\u00f6stericinin tuttu\u011fu bellek adresinde uygulanacakt\u0131r.<\/p>\n<p>Her\u015feyden \u00f6nce \u015funu tekrardan hat\u0131rlayarak konumuza devam edelim; pointer referans\u0131n\u0131 int\/uint gibi tam say\u0131lara cast edersek e\u011fer i\u015faret\u00e7inin tuttu\u011fu bellek adresine eri\u015febilmekteyiz. Bunun i\u00e7in a\u015fa\u011f\u0131daki \u00f6rnek kod blo\u011funu incelemeniz yeterlidir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            unsafe\r\n            {\r\n                int i = 10;\r\n                int* ipointer = &amp;i;\r\n                Console.WriteLine((int)ipointer);\r\n            }\r\n<\/pre>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6stericilerde-Aritmatik-\u0130\u015flemler-\u2013-VI.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6263\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6stericilerde-Aritmatik-\u0130\u015flemler-\u2013-VI.png\" alt=\"C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6stericilerde Aritmatik \u0130\u015flemler \u2013 VI\" width=\"63\" height=\"51\" \/><\/a><br \/>\n\u00d6nceki makalelerimizde de\u011findi\u011fimiz bu hususu \u00f6ncelikle hat\u0131rlatmam\u0131n sebebi, birazdan detayland\u0131raca\u011f\u0131m\u0131z g\u00f6stericiler \u00fczerindeki yapaca\u011f\u0131m\u0131z aritmatik i\u015flemlerdeki neticeleri bu bellek adresleri \u00fczerinde elde edece\u011fimizdendir.<\/p>\n<blockquote><p><strong><em>Tekrar ediyorum, g\u00f6stericiye yapaca\u011f\u0131m\u0131z herhangi bir aritmatik i\u015flem neticesinde o g\u00f6stericinin tuttu\u011fu bellek adresindeki de\u011fere g\u00f6sterici t\u00fcr\u00fcn\u00fcn i\u00e7erdi\u011fi byte say\u0131s\u0131 kadar i\u015flem yapmak demektir.<\/em><\/strong><\/p><\/blockquote>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/03\/tablo1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/03\/tablo1.jpg\" alt=\"De\u011fi\u015fken Tipleri\" width=\"921\" height=\"508\" class=\"aligncenter size-full wp-image-38\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/03\/tablo1.jpg 921w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/03\/tablo1-300x165.jpg 300w\" sizes=\"auto, (max-width: 921px) 100vw, 921px\" \/><\/a><br \/>\nYukar\u0131daki tabloda t\u00fcrlerin ka\u00e7 byte oldu\u011funu g\u00f6rmektesiniz.<\/p>\n<p>\u015e\u00f6yle bir \u00f6rnek vermek gerekirse;<br \/>\nE\u011fer ki &#8220;int&#8221; t\u00fcr\u00fcnden bir g\u00f6sterici ile &#8220;1&#8221; de\u011ferini toplad\u0131\u011f\u0131m\u0131z vakit g\u00f6stericinin i\u015faretledi\u011fi bellek adresi &#8220;4 byte&#8221; artt\u0131r\u0131lacakt\u0131r. Yok e\u011fer &#8220;1&#8221; de\u011feriyle de\u011fil &#8220;3&#8221; de\u011feriyle toplad\u0131\u011f\u0131m\u0131z vakit g\u00f6stericinin i\u015faretledi\u011fi bellek adresi &#8220;12 byte&#8221; artt\u0131r\u0131lacakt\u0131r.<\/p>\n<p>Benzer mant\u0131kla; e\u011fer ki &#8220;char&#8221; t\u00fcr\u00fcnden bir g\u00f6stericiyi &#8220;2&#8221; de\u011feri ile toplad\u0131\u011f\u0131m\u0131zda g\u00f6stericinin i\u015faretledi\u011fi bellek adresi &#8220;4 byte&#8221; artt\u0131r\u0131lacakt\u0131r. Yok e\u011fer &#8220;1&#8221; de\u011ferini \u00e7\u0131kar\u0131rsak e\u011fer bu seferde g\u00f6stericinin i\u015faretledi\u011fi bellek adresi &#8220;2 byte&#8221; azalt\u0131lacakt\u0131r.<\/p>\n<p>Birazdan kodlar \u00fczerinden pratik \u00f6rneklerle gidece\u011fiz. Amma velakin \u00f6rneklerimize gelmeden bu i\u015flemler i\u00e7in hangi operat\u00f6rleri kullanabilmekteyiz onlara bakal\u0131m&#8230;<\/p>\n<p><em><strong>+, -, &#8211;, ++, -=, +=<\/strong><\/em> bu operat\u00f6rlerin hepsini g\u00f6n\u00fcl rahatl\u0131\u011f\u0131yla kullanabilirsiniz.<\/p>\n<p>\u015eimdi a\u015fa\u011f\u0131daki kod blo\u011funu inceleyiniz.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            unsafe\r\n            {\r\n                int* pointer1 = (int*)100; \/\/ 4 byte\r\n                char* pointer2 = (char*)100; \/\/ 2 byte\r\n                bool* pointer3 = (bool*)100; \/\/ 2 byte\r\n                double* pointer4 = (double*)100; \/\/ 8 byte\r\n                decimal* pointer5 = (decimal*)100; \/\/ 16 byte\r\n                byte* pointer6 = (byte*)100; \/\/ 1 byte\r\n\r\n                pointer1 += 4; \/\/ 4 x 4 = 16 byte artacakt\u0131r.\r\n                pointer2 += 2; \/\/ 2 x 2 = 4 byte artacakt\u0131r.\r\n                pointer3++; \/\/ 2 x 1 = 2 byte artacakt\u0131r.\r\n                pointer4--; \/\/ 8 x 1 = 8 byte azalacakt\u0131r.\r\n                pointer5 = pointer5 - 5; \/\/ 16 x 5 = 80 byte azalacakt\u0131r.\r\n                pointer6 -= 10; \/\/ 1 x 10 = 10 byte azalacakt\u0131r.\r\n\r\n                Console.WriteLine((uint)pointer1);\r\n                Console.WriteLine((uint)pointer2);\r\n                Console.WriteLine((uint)pointer3);\r\n                Console.WriteLine((uint)pointer4);\r\n                Console.WriteLine((uint)pointer5);\r\n                Console.WriteLine((uint)pointer6);\r\n            }\r\n<\/pre>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6stericilerde-Aritmatik-\u0130\u015flemler-\u2013-VI-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6stericilerde-Aritmatik-\u0130\u015flemler-\u2013-VI-1.png\" alt=\"C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6stericilerde Aritmatik \u0130\u015flemler \u2013 VI\" width=\"44\" height=\"131\" class=\"aligncenter size-full wp-image-6276\" \/><\/a><br \/>\nG\u00f6r\u00fcld\u00fc\u011f\u00fc \u00fczere aritmatik i\u015flemler bu \u015fekilde bu mant\u0131kla ger\u00e7ekle\u015ftirilmektedir.<\/p>\n<p>Konuyu peki\u015ftirmek mahiyetinde a\u015fa\u011f\u0131daki \u00f6rne\u011fide incelemenizi tavsiye ediyorum.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            unsafe\r\n            {\r\n                int i = 3; \/\/ 4 byte\r\n                int* ipointer = &amp;i;\r\n                Console.WriteLine((uint)ipointer);\r\n                ipointer += 3; \/\/ 4 x 3 = 12 byte artacakt\u0131r.\r\n                Console.WriteLine((uint)ipointer);\r\n            }\r\n<\/pre>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6stericilerde-Aritmatik-\u0130\u015flemler-\u2013-VI-2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6stericilerde-Aritmatik-\u0130\u015flemler-\u2013-VI-2.png\" alt=\"C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6stericilerde Aritmatik \u0130\u015flemler \u2013 VI\" width=\"73\" height=\"64\" class=\"aligncenter size-full wp-image-6278\" \/><\/a><\/p>\n<h4>\u0130ki G\u00f6sterici Aras\u0131nda \u00c7\u0131karma \u0130\u015flemi<\/h4>\n<p>G\u00f6stericiler sabit tamsay\u0131 de\u011ferlerinin d\u0131\u015f\u0131nda birde kendi aralar\u0131nda \u00e7\u0131karma aritmati\u011fine tabi tutulabilirler. Burada dikkat edilmesi gereken tek unsur iki i\u015faret\u00e7ininde ayn\u0131 veri t\u00fcr\u00fcnden olmas\u0131 gerekmektedir.<\/p>\n<p>Ayriyetten yap\u0131lan \u00e7\u0131karma i\u015flemi neticesinde bir g\u00f6sterici \u00fcretilmemektedir. \u0130\u015flem g\u00f6stericilerin tuttuklar\u0131 bellek adreslerinin fark\u0131n\u0131n i\u015faret\u00e7i t\u00fcr\u00fcn\u00fcn byte de\u011ferine b\u00f6l\u00fcnmesiyle sonu\u00e7lanmakta ve bu neticeyi bize geri d\u00f6nd\u00fcrmektedir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            unsafe\r\n            {\r\n                int* pointer1 = (int*)500;\r\n                int* pointer2 = (int*)400;\r\n                long Sonuc = pointer1 - pointer2; \/\/ (500 - 400) \/ 4(byte) = 25;\r\n                Console.WriteLine(Sonuc);\r\n            }\r\n<\/pre>\n<p>Yukar\u0131daki kod blo\u011funu incelerseniz e\u011fer iki pointer aras\u0131nda yap\u0131lan \u00e7\u0131karma i\u015flemi neticesinde sonu\u00e7 &#8220;long&#8221; olarak elde edilmektedir. Ba\u011f\u0131nt\u0131 olarak ise iki bellek adresleri birbirlerinden \u00e7\u0131kar\u0131lmakta ve pointer t\u00fcr\u00fcn\u00fcn(int) byte de\u011ferine(4 byte) b\u00f6l\u00fcnmektedir. Ee haliyle bu \u015fekilde sonu\u00e7 olarak 25 de\u011ferini elde etmekteyiz.<\/p>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6stericilerde-Aritmatik-\u0130\u015flemler-\u2013-VI-3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6stericilerde-Aritmatik-\u0130\u015flemler-\u2013-VI-3.png\" alt=\"C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6stericilerde Aritmatik \u0130\u015flemler \u2013 VI\" width=\"39\" height=\"47\" class=\"aligncenter size-full wp-image-6284\" \/><\/a><\/p>\n<p><strong>Peki bu i\u015flem ne i\u015fe yaramaktad\u0131r?<\/strong><br \/>\nBu i\u015flem iki g\u00f6stericinin aras\u0131ndaki fark\u0131 byte t\u00fcr\u00fcnden elde etmemizi sa\u011flamaktad\u0131r. Yani anlayaca\u011f\u0131n\u0131z ekleme yahut \u00e7\u0131karma neticesinde elde edilen sonu\u00e7lar\u0131n bir sa\u011flamas\u0131d\u0131r diyebiliriz.<\/p>\n<h4>void T\u00fcr\u00fc \u00dczerine Aritmatik \u0130\u015flemler<\/h4>\n<p>void g\u00f6stericilerde herhangi bir t\u00fcr bilgisi olmad\u0131\u011f\u0131 i\u00e7in aritmatik i\u015flemler yap\u0131lmamaktad\u0131r. \u00c7\u00fcnk\u00fc yukar\u0131da g\u00f6rd\u00fc\u011f\u00fcn\u00fcz gibi g\u00f6stericinin t\u00fcr\u00fcne \u00f6zel byte de\u011feri hesaba kat\u0131lmakta ve i\u015flem ger\u00e7ekle\u015ftirilmektedir. Ee haliyle void g\u00f6stericisinin t\u00fcr\u00fc belli olmad\u0131\u011f\u0131 i\u00e7in ne kadarl\u0131k bir byte de\u011ferinin hesaba kat\u0131laca\u011f\u0131da bilinmeyece\u011finden dolay\u0131 bu t\u00fcr g\u00f6sterciler \u00fczerinde aritmatik i\u015flemler yasaklanm\u0131\u015ft\u0131r.<\/p>\n<p>Evet arkada\u015flar. G\u00f6stericilerde aritmatik i\u015flemleri teferruatl\u0131ca irdeledi\u011fimiz bu dolu ve yorucu makaleye son verme zaman\u0131 gelmi\u015f bulunmaktad\u0131r. Sonraki makalemizde fixed keyword\u00fc \u00fczerinde isti\u015fare edece\u011fimizi bildiririm.<\/p>\n<p>\u015eimdilik g\u00f6r\u00fc\u015fmek \u00fczere&#8230;<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar&#8230;<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Merhaba, \u00d6nceki C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6stericiler Aras\u0131nda T\u00fcr D\u00f6n\u00fc\u015f\u00fcmleri \u2013 V ba\u015fl\u0131kl\u0131 makalemizde g\u00f6stericilerde t\u00fcr d\u00f6n\u00fc\u015f\u00fcmlerini ele alm\u0131\u015ft\u0131k. \u015eimdi ise g\u00f6stericiler \u00fczerinde aritmatik i\u015flemleri de\u011ferlendiriyor olaca\u011f\u0131z. G\u00f6stericiler \u0130le Sabit Tamsay\u0131 De\u011ferlerini Toplama\/\u00c7\u0131karma G\u00f6stericiler \u00fczerinde&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":3014,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[1784,1787,1761,1785,1783,1748,1786],"class_list":["post-6262","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-sharp-c","tag-c-gostericiler","tag-c-gostericilerde-aritmatik-islemler","tag-cta-gosterici","tag-gostericiler-pointer","tag-gostericilerde-aritmatik-islemler","tag-pointer","tag-pointer-aritmatik-islemler"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/6262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=6262"}],"version-history":[{"count":0,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/6262\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/3014"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=6262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=6262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=6262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}