﻿
{"id":6156,"date":"2017-05-06T13:18:11","date_gmt":"2017-05-06T13:18:11","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=6156"},"modified":"2017-05-06T13:18:11","modified_gmt":"2017-05-06T13:18:11","slug":"cta-gostericipointer-gosterici-bildirimi-ve-gosterici-operatorleri-iv","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/cta-gostericipointer-gosterici-bildirimi-ve-gosterici-operatorleri-iv\/","title":{"rendered":"C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6sterici Bildirimi ve G\u00f6sterici Operat\u00f6rleri \u2013 IV"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Bir \u00f6nceki i\u00e7eri\u011fimizde <a href=\"http:\/\/www.gencayyildiz.com\/blog\/cta-gostericipointer-gosterici-bildirimi-ve-gosterici-operatorleri-iii\/\" target=\"_blank\" rel=\"noopener noreferrer\">C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6sterici Bildirimi ve G\u00f6sterici Operat\u00f6rleri \u2013 III<\/a> ba\u015fl\u0131\u011f\u0131 alt\u0131nda g\u00f6stericilerde, g\u00f6sterici bildirimi \u00fczerine giri\u015f ve detay niteli\u011finde bir irdelemede bulunmu\u015ftuk. Bu makalemizde ise konumuzun ikinci k\u0131sm\u0131 olan g\u00f6sterici operat\u00f6rleri \u00fczerine konu\u015fuyor olaca\u011f\u0131z.<\/p>\n<p>Yukar\u0131da vermi\u015f oldu\u011fum bir \u00f6nceki makalenin i\u00e7eri\u011finde oldu\u011fu gibi g\u00f6sterici bildiriminde *(asterisk\/y\u0131ld\u0131z) karakterini kullan\u0131yorduk. \u00d6ncelikle * karakteri ile tan\u0131mlanm\u0131\u015f bir g\u00f6stericinin i\u015faretleyece\u011fi, bir de\u011fi\u015fken bellek adresini bize getirecek olan &amp; operat\u00f6r\u00fc \u00fczerine de\u011finece\u011fiz.<\/p>\n<h4>&amp;(Ampersand) Operat\u00f6r\u00fc<\/h4>\n<p>&amp; operat\u00f6r\u00fc, <em>adres operat\u00f6r\u00fc<\/em> olarak bilinmektedir. De\u011fi\u015fkenlerin bellekteki adreslerini elde etmemizi sa\u011flar. Daha do\u011frusu bu operat\u00f6r hangi de\u011fi\u015fken \u00fczerinde kullan\u0131l\u0131yorsa o de\u011fi\u015fken tipinde bir pointer \u00fcretmektedir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            unsafe\r\n            {\r\n                int a = 3; \/\/De\u011fi\u015fken tan\u0131mland\u0131.\r\n                int* apointer; \/\/Pointer tan\u0131mland\u0131.\r\n                apointer = &amp;a; \/\/a de\u011fi\u015fkeninin bellek adresi &amp; operat\u00f6r\u00fc ile elde edilip; bu adres, apointer g\u00f6stericisi ile i\u015faretlenmi\u015ftir.\r\n            }\r\n        }\r\n<\/pre>\n<p>Yukar\u0131daki kod blo\u011funa bakarsan\u0131z e\u011fer &amp; operat\u00f6r\u00fc ile normal bir de\u011fi\u015fken olan &#8220;a&#8221; de\u011fi\u015fkeni &#8220;apointer&#8221; isimli g\u00f6sterici ile i\u015faretlenmi\u015f bulunmaktad\u0131r. Asl\u0131nda buradaki kullan\u0131mda &amp; operat\u00f6r\u00fc direkt olarak &#8220;a&#8221; de\u011fi\u015fkeninin tipinde bir pointer \u00fcretmektedir. Bunuda a\u015fa\u011f\u0131daki ekran g\u00f6r\u00fcnt\u00fcs\u00fcnden daha net bir \u015fekilde g\u00f6rebilirsiniz.<\/p>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6166\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV.png\" alt=\"C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6sterici Bildirimi ve G\u00f6sterici Operat\u00f6rleri \u2013 IV\" width=\"236\" height=\"178\" \/><\/a><\/p>\n<p>\u00dcretilen pointer &#8220;a&#8221; de\u011fi\u015fkeninin bellekteki adresini tutan bir pointerd\u0131r. Eee haliyle bu pointer\u0131 da &#8220;apointer&#8221; isimli pointer ile refere etmekteyiz.<\/p>\n<p><strong>Peki bu yapt\u0131\u011f\u0131m\u0131z i\u015flem neticesinde aslen neler oluyor?<\/strong><br \/>\nYukar\u0131daki yapm\u0131\u015f oldu\u011fumuz \u00e7al\u0131\u015fma neticesinde her ne kadar iki adet de\u011fi\u015fken tan\u0131mlam\u0131\u015f gibi g\u00f6r\u00fcnsede asl\u0131nda bir adet de\u011fi\u015fken tan\u0131mlanm\u0131\u015ft\u0131r. A\u015fa\u011f\u0131daki g\u00f6rselde de a\u00e7\u0131k\u00e7a g\u00f6sterildi\u011fi gibi &#8220;a&#8221; de\u011fi\u015fkeninin bellek adresi biryandan da &#8220;apointer&#8221; de\u011fi\u015fkeni taraf\u0131ndan i\u015faretlendi\u011fi\/g\u00f6sterildi\u011fi i\u00e7in asl\u0131nda iki referansta bellekteki ayn\u0131 alan\u0131 refere etmektedir.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6170\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-1.png\" alt=\"C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6sterici Bildirimi ve G\u00f6sterici Operat\u00f6rleri \u2013 IV\" width=\"485\" height=\"178\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-1.png 485w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-1-300x110.png 300w\" sizes=\"auto, (max-width: 485px) 100vw, 485px\" \/><\/a><br \/>\nHatta birazdan pointerlar \u00fczerinden g\u00f6sterdikleri bellek adreslerine m\u00fcdahale etti\u011fimizde de\u011fi\u015fkeninde de\u011ferinin de\u011fi\u015fti\u011fini g\u00f6rece\u011fiz. \u00c7\u00fcnk\u00fc ikiside ayn\u0131 noktay\u0131 refere etmektedirler. Velhas\u0131l oraya geldi\u011fimizde size bu noktay\u0131 hat\u0131rlataca\u011f\u0131m&#8230;<\/p>\n<blockquote><p><strong><em>&amp; operat\u00f6r\u00fc struct, enum ve de\u011fer tipli de\u011fi\u015fkenler \u00fczerinde kullan\u0131labilir.<\/em><\/strong><\/p><\/blockquote>\n<p>Aynen a\u015fa\u011f\u0131da oldu\u011fu gibi.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    struct MyStruct { }\r\n    enum MyEnum { }\r\n    class Program\r\n    {\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            unsafe\r\n            {\r\n                #region Struct\r\n                MyStruct ms;\r\n                MyStruct* mspointer;\r\n                mspointer = &amp;ms;\r\n                #endregion\r\n                #region Enum\r\n                MyEnum me;\r\n                MyEnum* mepointer;\r\n                mepointer = &amp;me;\r\n                #endregion\r\n                #region Value Type\r\n                int a = 3;\r\n                int* apointer = &amp;a;\r\n                #endregion\r\n            }\r\n        }\r\n    }\r\n<\/pre>\n<h4>* Operat\u00f6r\u00fc<\/h4>\n<p>G\u00f6sterici bildiriminde kulland\u0131\u011f\u0131m\u0131z operat\u00f6rle ayn\u0131 karakter olan * operat\u00f6r\u00fc iki farkl\u0131 ama\u00e7 i\u00e7in tasarlanm\u0131\u015ft\u0131r. Birisi \u015fuana kadar kulland\u0131\u011f\u0131m\u0131z ve i\u015fte \u015fimdi de\u011findi\u011fim gibi g\u00f6sterici bildiriminde kullan\u0131lmaktayken bir di\u011feri ise bir pointer\u0131n i\u015faretledi\u011fi adresteki bilgileri elde etmek yahut g\u00fcncellemek yani bellek adresinin de\u011fer alan\u0131na direkt olarak m\u00fcdahale etmek i\u00e7in kullan\u0131l\u0131r.<\/p>\n<p>E\u011fer ki ikinci ama\u00e7 do\u011frultusunda bu operat\u00f6r kullan\u0131l\u0131rsa <em>i\u00e7erik operat\u00f6r\u00fc<\/em> olarak nitelendirilmektedir. * operat\u00f6r\u00fc hangi t\u00fcr pointer ile kullan\u0131l\u0131rsa bellekte m\u00fcdahale edilecek bilgi miktar\u0131 o t\u00fcr\u00fcn b\u00fcy\u00fckl\u00fc\u011f\u00fc ile ayn\u0131 olacakt\u0131r.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            unsafe\r\n            {\r\n                int a = 3; \/\/De\u011fi\u015fken tan\u0131mland\u0131.\r\n                int* apointer;\/\/Pointer tan\u0131mland\u0131.\r\n                apointer = &amp;a; \/\/a de\u011fi\u015fkeninin bellek adresi apointer taraf\u0131ndan i\u015faretlendi.\r\n\r\n                *apointer = 10; \/\/apointer\u0131n i\u015faret etti\u011fi bellekteki de\u011fer 10 olarak yenilendi.\r\n\r\n                Console.WriteLine($&quot;a de\u011fi\u015fkeni : {a}\\napointer g\u00f6stericisi : {*apointer}&quot;);\r\n                \/\/Burada ise apointer\u0131n i\u015faret etti\u011fi bellekteki de\u011fer elde edilmi\u015ftir.\r\n                Console.Read();\r\n            }\r\n        }\r\n<\/pre>\n<p>Yukar\u0131daki kod blo\u011funu incelemeniz gayet yeterlidir. Gerekli a\u00e7\u0131klamalar\u0131 ilgili kod sat\u0131rlar\u0131n\u0131n yan\u0131na yapm\u0131\u015f bulunmaktay\u0131m. Dikkat ederseniz &#8220;*apointer&#8221; ifadesi ile &#8220;apointer&#8221; i\u015faret\u00e7isindeki de\u011fere m\u00fcdahale edebiliyor ya da de\u011feri elde edebiliyoruz. E\u011fer ki projemizi derleyip \u00e7al\u0131\u015ft\u0131r\u0131rsak a\u015fa\u011f\u0131daki sonu\u00e7la kar\u015f\u0131la\u015faca\u011f\u0131z.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6180\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-2.png\" alt=\"C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6sterici Bildirimi ve G\u00f6sterici Operat\u00f6rleri \u2013 IV.PNG\" width=\"213\" height=\"45\" \/><\/a><\/p>\n<p>\u015eimdi burada makalemizin giri\u015finde adresini vermi\u015f oldu\u011fum \u00f6nceki makalemizden sinyal verdi\u011fim bir noktaya de\u011finmek istiyorum.<em>(<a href=\"http:\/\/www.gencayyildiz.com\/blog\/cta-gostericipointer-gosterici-bildirimi-ve-gosterici-operatorleri-iii\" target=\"_blank\" rel=\"noopener noreferrer\">\u00d6nceki makaleye buradan da eri\u015febilirsiniz<\/a>)<\/em> Hani ilgili makalenin \u015f\u00f6yle sonlar\u0131na do\u011fru g\u00f6sterici bildiriminde a\u015fa\u011f\u0131daki gibi \u00e7oklu bir kullan\u0131mda bulunmu\u015ftuk.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            unsafe\r\n            {\r\n                int*** i;\r\n            }\r\n<\/pre>\n<p>Heh i\u015fte bu kullan\u0131mla ilgili i\u00e7erik operat\u00f6r\u00fcn\u00fc kullan\u0131rken dikkat etmemiz gerekmektedir. Daha do\u011frusu daha kompleks bir \u015fekilde yakla\u015f\u0131m sergilememiz gerekecektir. Bunun nedenini \u015f\u00f6yle izah edelim;<\/p>\n<p>Yukar\u0131daki kullan\u0131mda &#8220;int&#8221; tipinde bir g\u00f6stericiyi i\u015faret eden (<span style=\"color: #ff0000;\">int*<\/span>**) bir ba\u015fka g\u00f6stericiyi (<span style=\"color: #ff0000;\">int**<\/span>*) i\u015faret eden pointer (<span style=\"color: #ff0000;\">int***<\/span>) temsil edilmektedir.<\/p>\n<p>Ee haliyle bu pointer\u0131n i\u015faretledi\u011fi bellek adresindeki de\u011fere m\u00fcdahale etmek yahut ula\u015fmak i\u00e7in \u015fu mant\u0131kta hareket etmemiz gerekecektir;<\/p>\n<p>i pointer\u0131n\u0131n bellek adresini tuttu\u011fu (**<span style=\"color: #ff0000;\">*i<\/span>) pointer\u0131n (*<span style=\"color: #ff0000;\">**i<\/span>) tekrardan bellek adresini tuttu\u011fu pointer\u0131n (<span style=\"color: #ff0000;\">***i<\/span>) de\u011ferine m\u00fcdahale et.<\/p>\n<p>Biraz kompleks gibi gelebilir ama a\u015fa\u011f\u0131daki \u00f6rnek konuyu birazdaha anla\u015f\u0131l\u0131r hale getirecektir.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-3.png\" alt=\"C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6sterici Bildirimi ve G\u00f6sterici Operat\u00f6rleri \u2013 IV.PNG\" width=\"242\" height=\"217\" class=\"aligncenter size-full wp-image-6191\" \/><\/a><br \/>\nDikkat ederseniz \u00e7oklu olan &#8220;ii&#8221; isimli pointer\u0131n i\u00e7erik operat\u00f6r\u00fc ile de\u011ferini talep etti\u011fimiz zaman hata vermektedir. Bunun sebebi yukar\u0131daki mant\u0131kta da anlatmak istedi\u011fim gibi &#8220;ii&#8221; pointer\u0131 arka planda &#8220;i&#8221; pointer\u0131n\u0131n bellek adresini i\u015faretlemi\u015f bulunmaktad\u0131r. Haliyle i\u00e7erik operat\u00f6r\u00fc &#8220;*ii&#8221; \u015feklinde kullan\u0131ld\u0131\u011f\u0131nda asl\u0131nda &#8220;ii&#8221; pointer\u0131n\u0131n de\u011feri olan &#8220;i&#8221; pointer\u0131 getirilmektedir. Ee biliyoruz ki pointerlar direkt olarak \u00e7a\u011fr\u0131ld\u0131klar\u0131nda de\u011fer vermemektedir, i\u00e7erik operat\u00f6r\u00fcn\u00fc kullanmam\u0131z gerekmektedir. Halbuki burada &#8220;*ii&#8221; kullan\u0131m\u0131 kullan\u0131ld\u0131\u011f\u0131 yere &#8220;i&#8221; pointer\u0131n\u0131 getirmektedir. Nihai sonucu elde etmek ve hatas\u0131z bir syntax yap\u0131s\u0131nda kod yazmak istiyorsak &#8220;i&#8221; pointer\u0131na da a\u015fa\u011f\u0131daki gibi bir adet i\u00e7erik operat\u00f6r\u00fc vermemiz gerekmektedir.<\/p>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-4.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-4.png\" alt=\"C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6sterici Bildirimi ve G\u00f6sterici Operat\u00f6rleri \u2013 IV.PNG\" width=\"238\" height=\"215\" class=\"aligncenter size-full wp-image-6193\" \/><\/a><\/p>\n<p>\u0130\u015fte yukar\u0131daki gibi bir \u00e7al\u0131\u015fma yaparsak sorunumuz ortadan kalkmaktad\u0131r. &#8220;**ii&#8221; kullan\u0131m\u0131nda ilk &#8220;*&#8221; karakteri &#8220;ii&#8221; pointer\u0131n\u0131n i\u015faret etti\u011fi bellek adresindeki de\u011feri getirmesi i\u00e7in iken, ikinci &#8220;*&#8221; karakteri ise &#8220;ii&#8221; pointer\u0131n\u0131n i\u015faret etti\u011fi bellek adresinden gelen &#8220;i&#8221; pointer\u0131n\u0131n i\u015faret etti\u011fi bellek adresindeki de\u011feri getirmesi i\u00e7indir. <\/p>\n<p>A\u015fa\u011f\u0131daki kod blo\u011funu incelerseniz e\u011fer \u015f\u00f6yle bir genellemeye varabiliriz; \u00e7oklu kombinasyon ne kadar derinse i\u00e7erik operat\u00f6r\u00fcn\u00fcn kullan\u0131m\u0131da ayn\u0131 orant\u0131da derin olmal\u0131d\u0131r. <\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            unsafe\r\n            {\r\n                int a = 5;\r\n                int* i = &amp;a;\r\n                int** ii = &amp;i;\r\n                int*** iii = &amp;ii;\r\n                int**** iiii = &amp;iii;\r\n                int***** iiiii = &amp;iiii;\r\n\r\n                Console.WriteLine(*****iiiii);\r\n\r\n                Console.Read();\r\n            }\r\n        }\r\n<\/pre>\n<p>Bu zor ve me\u015fakkatli noktadan sonra i\u00e7erik operat\u00f6r\u00fcm\u00fczle ilgili anlat\u0131m\u0131m\u0131za devam edelim.<\/p>\n<blockquote><p><strong><em>*(i\u00e7erik) operat\u00f6r\u00fcn\u00fcn operand\u0131 bir adres olmak zorundad\u0131r.<\/em><\/strong><\/p><\/blockquote>\n<p>Hi\u00e7 dikkat ettiniz mi? bilmiyorum ama g\u00f6stericilerin kullan\u0131m mant\u0131\u011f\u0131 aynen referans tipli de\u011fi\u015fkenlerin kullan\u0131m mant\u0131\u011f\u0131yla olduk\u00e7a benzerlik g\u00f6stermektedir. Yani bir nesne birden fazla referans noktas\u0131 taraf\u0131ndan i\u015faretlense dahi t\u00fcm referanslar ayn\u0131 nesneyi g\u00f6sterdi\u011fi i\u00e7in nesne \u00fczerindeki t\u00fcm de\u011fi\u015fiklikler referans farketmeksizin yans\u0131t\u0131lacakt\u0131r.<\/p>\n<p>Haliyle bu benzerli\u011fi a\u015fa\u011f\u0131daki gibi k\u0131yaslarsak daha net bir tablo ortaya \u00e7\u0131kmaktad\u0131r.<\/p>\n<table style=\"width:100%;\">\n<thead>\n<tr>\n<th>G\u00f6stericiler<\/th>\n<th>Referans Tipli De\u011fi\u015fkenler<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-7.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-7.png\" alt=\"C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6sterici Bildirimi ve G\u00f6sterici Operat\u00f6rleri \u2013 IV.PNG\" width=\"449\" height=\"207\" class=\"aligncenter size-full wp-image-6209\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-7.png 449w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-7-300x138.png 300w\" sizes=\"auto, (max-width: 449px) 100vw, 449px\" \/><\/a><\/td>\n<td><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-5.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-5.png\" alt=\"C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6sterici Bildirimi ve G\u00f6sterici Operat\u00f6rleri \u2013 IV\" width=\"403\" height=\"333\" class=\"aligncenter size-full wp-image-6204\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-5.png 403w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-5-300x248.png 300w\" sizes=\"auto, (max-width: 403px) 100vw, 403px\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-8.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-8.png\" alt=\"C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6sterici Bildirimi ve G\u00f6sterici Operat\u00f6rleri \u2013 IV\" width=\"191\" height=\"42\" class=\"aligncenter size-full wp-image-6210\" \/><\/a><\/td>\n<td><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-6.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-6.png\" alt=\"C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6sterici Bildirimi ve G\u00f6sterici Operat\u00f6rleri \u2013 IV.PNG\" width=\"152\" height=\"39\" class=\"aligncenter size-full wp-image-6207\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>G\u00f6stericilerle, referans tipli de\u011fi\u015fkenler aras\u0131ndaki temel fark bellekte bar\u0131nd\u0131r\u0131lma alanlar\u0131n\u0131n farkl\u0131 olmas\u0131d\u0131r. G\u00f6stericiler stack, referans tipli de\u011fi\u015fkenler ise heap k\u0131sm\u0131nda burundurulmaktad\u0131r.<\/p>\n<p>\u015eimdi ise arkada\u015flar C# programlama dilinin t\u00fcr g\u00fcvenli\u011fine ne kadar \u00f6nem verdi\u011fini resmedecek bir \u00f6rnek \u00fczerinden konumuza devam edece\u011fiz.<\/p>\n<p>C# t\u00fcr g\u00fcvenli\u011fini y\u00fcksek derecede \u00f6nemseyen bir programlama dilidir. Hele hele belle\u011fe direkt eri\u015fim s\u00f6z konusu oldu\u011fu durumlarda bu \u00f6nem kat be kat artmaktad\u0131r. Peki neden? Bu nedeni siz sorgularken bir yandan da a\u015fa\u011f\u0131daki ekran g\u00f6r\u00fcnt\u00fcs\u00fcn\u00fc inceleyiniz.<\/p>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-9.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-9.png\" alt=\"C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6sterici Bildirimi ve G\u00f6sterici Operat\u00f6rleri \u2013 IV.PNG\" width=\"221\" height=\"148\" class=\"aligncenter size-full wp-image-6214\" \/><\/a><br \/>\nDikkat ederseniz yukar\u0131da yap\u0131lan \u00e7al\u0131\u015fma derlenmemi\u015f, hata vermi\u015ftir. Bu hatan\u0131n sebebi &#8220;pointer&#8221; isimli g\u00f6stericinin hangi adresi tuttu\u011funun belli olmamas\u0131ndan kaynaklanmaktad\u0131r. E\u011fer ki bir pointera herhangi bir bellek adresi tutturmadan i\u00e7erik operat\u00f6r\u00fc(*) ile de\u011fer atamak yahut de\u011ferini okumak isterseniz yukar\u0131daki gibi program derlenmeyecektir.<\/p>\n<p><em><strong>Peki adresi belli olmayan bir pointera neden de\u011fer atayam\u0131yoruz?<\/strong><\/em><br \/>\nAsl\u0131nda C yahut C++ programlama dillerinde \u00e7al\u0131\u015f\u0131yor olsayd\u0131k hata almaks\u0131z\u0131n bu tarz bir kullan\u0131mda sak\u0131ncal\u0131da olsa bulunabilirdik. Her\u015feyden \u00f6nce gelin bu tarz bir kullan\u0131m\u0131n neden sak\u0131ncal\u0131 oldu\u011funa bakal\u0131m. Ard\u0131ndan kullan\u0131p, kullanamama durumundaki de\u011ferlendirmeyi size b\u0131rakaca\u011f\u0131m.<\/p>\n<p><em>&#8220;int* pointer&#8221;<\/em> \u015feklinde g\u00f6sterici tan\u0131mland\u0131\u011f\u0131 an ilgili g\u00f6sterici rastgele bir adres de\u011feri ile olu\u015fturulmaktad\u0131r. Haliyle i\u015faretlenen adres rastgele oldu\u011fu i\u00e7in o anki bellekte herhangi bir kritik adres yahut \u00f6nemli ve eri\u015filmesi sak\u0131ncal\u0131 de\u011fi\u015fken adresi olabilir. Velhas\u0131l bilmedi\u011fimiz bir adresteki veriye m\u00fcdahale etmek tahmin edemeyece\u011fimiz sonu\u00e7lara sebep olabilir.<\/p>\n<p>\u0130\u015fin daha da k\u00f6t\u00fcs\u00fc g\u00f6stericiye verilen adres rastgele oldu\u011fu i\u00e7in yaz\u0131l\u0131m test a\u015famas\u0131ndayken olas\u0131 hatalarla kar\u015f\u0131la\u015fmayabiliriz. Adreslerin rastgele olmas\u0131 gibi hatalar\u0131nda rastgele olma ihtimalini g\u00f6z ard\u0131 etmemek laz\u0131m. Aksi taktirde piyasaya s\u00fcr\u00fclen yaz\u0131l\u0131mdan ara ara gelen hay\u0131rs\u0131z d\u00f6n\u00fctler ve pek iyimser olmayan kullan\u0131c\u0131 yorumlar\u0131n\u0131n yarataca\u011f\u0131 tela\u015f\u0131 ve mahcubiyeti d\u00fc\u015f\u00fcn\u00fcn.<\/p>\n<p>Tabi ki de bu tarz dezavantajlar g\u00f6stericileri anlams\u0131zla\u015ft\u0131rmas\u0131 ve de\u011fersizle\u015ftirmesi anlam\u0131na gelmemektedir. Sadece g\u00f6sterici kullan\u0131rken daha dikkatli, sa\u011flam ad\u0131mlarla hareket edilmesi gerekti\u011fini bilmeniz gerekmektedir.<\/p>\n<p>\u0130\u015fte bu sebepten dolay\u0131 C# programlama dilinde g\u00f6stericilere bellek adresi atamadan de\u011fer vermek ya da de\u011ferini elde etmek yasaklanm\u0131\u015ft\u0131r.<\/p>\n<h4>sizeof Operat\u00f6r\u00fc<\/h4>\n<p>sizeof operat\u00f6r\u00fc struct, enum ve temel veri t\u00fcrlerinin ne kadar alan kaplad\u0131klar\u0131n\u0131 verir. S\u0131n\u0131f yap\u0131lar\u0131 i\u00e7in sizeof operat\u00f6r\u00fc kullan\u0131lmaz. Genellikle struct yap\u0131lar\u0131 i\u00e7in kullan\u0131l\u0131r. Bunun sebebi genellikle temel veri t\u00fcrlerinin de\u011fer aral\u0131klar\u0131 bilinmesidir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    struct MyStruct { }\r\n    enum MyEnum { }\r\n    class Program\r\n    {\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            int sizeTemelVeriTuru = sizeof(int);\r\n            int sizeEnum = sizeof(MyEnum);\r\n\r\n            unsafe\r\n            {\r\n                int sizeStruct = sizeof(MyStruct);\r\n                Console.WriteLine($&quot;Temel Veri T\u00fcr\u00fc : {sizeTemelVeriTuru}&quot;);\r\n                Console.WriteLine($&quot;Enum : {sizeEnum}&quot;);\r\n                Console.WriteLine($&quot;Struct : {sizeStruct}&quot;);\r\n            }\r\n            Console.Read();\r\n        }\r\n    }\r\n<\/pre>\n<p>Burada dikkat etmeniz gereken nokta, sizeof operat\u00f6r\u00fcn\u00fc struct boyutunu \u00f6l\u00e7mek i\u00e7in kullacaksan\u0131z unsafe blo\u011fu aras\u0131nda bu i\u015flemi yapman\u0131z gerekmektedir.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-10.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-10.png\" alt=\"C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6sterici Bildirimi ve G\u00f6sterici Operat\u00f6rleri \u2013 IV.PNG\" width=\"157\" height=\"84\" class=\"aligncenter size-full wp-image-6228\" \/><\/a><br \/>\nAyriyetten struct i\u00e7erisine property ekledik\u00e7e propertynin t\u00fcr\u00fc ne ise struct&#8217;\u0131n boyutuda ona g\u00f6re artmaktad\u0131r.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    struct MyStruct\r\n    {\r\n        public int x { get; set; } \/\/+4\r\n        public bool y { get; set; } \/\/+4\r\n        public int z; \/\/+4\r\n    }\r\n    class Program\r\n    {\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            unsafe\r\n            {\r\n                int sizeStruct = sizeof(MyStruct);\r\n                Console.WriteLine($&quot;Struct : {sizeStruct}&quot;);\r\n            }\r\n            Console.Read();\r\n        }\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\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-11.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-G\u00f6sterici-Bildirimi-ve-G\u00f6sterici-Operat\u00f6rleri-\u2013-IV-11.png\" alt=\"C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6sterici Bildirimi ve G\u00f6sterici Operat\u00f6rleri \u2013 IV.PNG\" width=\"107\" height=\"61\" class=\"aligncenter size-full wp-image-6230\" \/><\/a><br \/>\nTabi burada dikkat edilmesi gereken bir di\u011fer husus ise sizeof operat\u00f6r\u00fcn\u00fcn kullan\u0131ld\u0131\u011f\u0131 struct i\u00e7erisinde referans t\u00fcr\u00fcnden bir property, de\u011fi\u015fken vs. olmamas\u0131 gerekmektedir. Aksi taktirde hata ile kar\u015f\u0131la\u015f\u0131lacakt\u0131r.<\/p>\n<p>Evet arkada\u015flar&#8230;<br \/>\nZor ve zahmetli bir makalemizin daha sonuna gelmi\u015f bulunmaktay\u0131z. San\u0131yorum ki g\u00f6sterici operat\u00f6rleri \u00fczerine tam teferruatl\u0131 bir i\u00e7erik ortaya koymu\u015f olduk. Sizler \u00f6\u011frendiklerinizi sindirme ve birazda dinlenme moduna ge\u00e7erken bendeniz ise bir sonraki makalemizin i\u00e7eri\u011fi olacak g\u00f6stericiler aras\u0131nda t\u00fcr d\u00f6n\u00fc\u015f\u00fcmleri \u00fczerine \u00e7al\u0131\u015fmaya ba\u015flayabilirim. <\/p>\n<p>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, Bir \u00f6nceki i\u00e7eri\u011fimizde C#\u2019ta G\u00f6sterici(Pointer) \u2013 G\u00f6sterici Bildirimi ve G\u00f6sterici Operat\u00f6rleri \u2013 III ba\u015fl\u0131\u011f\u0131 alt\u0131nda g\u00f6stericilerde, g\u00f6sterici bildirimi \u00fczerine giri\u015f ve detay niteli\u011finde bir irdelemede bulunmu\u015ftuk. Bu makalemizde ise konumuzun ikinci k\u0131sm\u0131 olan&#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":[897,1776,1775,1747,1746,1767,1768,1769,1777,1748,1779,1778],"class_list":["post-6156","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-sharp-c","tag-operatoru","tag-adres-operatoru","tag-c-ampersand-operatoru","tag-c-gosterici","tag-c-pointer","tag-gosterici","tag-gosterici-bildirimi","tag-gosterici-operatorleri","tag-icerik-operatoru","tag-pointer","tag-sizeof","tag-sizeof-operatoru"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/6156","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=6156"}],"version-history":[{"count":0,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/6156\/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=6156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=6156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=6156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}