1 / 11

Dersin Adı :ALGORİTMA GELİŞTİME TEKNİKLERİ Dersin Kodu :YBS501

8.HAFTA. Dersin Adı :ALGORİTMA GELİŞTİME TEKNİKLERİ Dersin Kodu :YBS501. Konu:İşaretçiler ( Pointer ). İŞARETÇİLER. İşaretçi bellekte belirli bir adresi işaret eden özel değişkenlerdir.

reed-zamora
Download Presentation

Dersin Adı :ALGORİTMA GELİŞTİME TEKNİKLERİ Dersin Kodu :YBS501

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 8.HAFTA Dersin Adı :ALGORİTMA GELİŞTİME TEKNİKLERİDersin Kodu :YBS501 Konu:İşaretçiler (Pointer) E-mail:speldek@bartin.edu.tr

  2. İŞARETÇİLER • İşaretçi bellekte belirli bir adresi işaret eden özel değişkenlerdir. • İşaretçi değişken normal veri tiplerinden birini depolamaktan çok belekteki belirli bir yerin adresini depolamak için kullanılır. • Daha açık ifade ile işaretçi, bellekte belirli bir yeri gösteren ve bu yerdeki içeriğe ulaşımı sağlayan bir dinamik değişkendir.

  3. İşaretçi Değişkeninin Tanımlanması normal değişken tanımlaması:int x; işaretçi değişken tanımlaması:int *p; X ‘in adresi İnt tipinde değişken p’nin adresi Adres değeri

  4. C++ Örnek • #include"stdafx.h" • #include<iostream> • usingnamespacestd; • int _tmain(intargc, _TCHAR* argv[]) • { • int i; • int *p; • i=16; • p=&i; • cout<<"i = "<<i<<endl<<"*p= "<<*p; • getchar(); • return 0; • }

  5. C++ Örneği • #include"stdafx.h" • #include<iostream> • usingnamespacestd; • int _tmain(intargc, _TCHAR* argv[]) • { • int i; • int *p; • i=16; • p=&i; • cout<<"i = "<<i<<endl<<"*p= "<<*p<<endl; • *p=32; • cout<<"i = "<<i<<endl<<"*p= "<<*p<<endl; • getchar(); • return 0; • }

  6. Normal Tanımlama • #include"stdafx.h" • #include<iostream> • usingnamespacestd; • int _tmain(intargc, _TCHAR* argv[]) • { • int i; • int p; • i=p=16; • cout<<"i = "<<i<<endl<<"p= "<<p<<endl; • p=32; • cout<<"i = "<<i<<endl<<"p= "<<p<<endl; • getchar(); • return 0; • }

  7. Hatırlatma:Referans Referans atamaları için illa fonksiyon çağırmamıza gerek yoktur: • #include"stdafx.h" • #include<iostream> • usingnamespace std; • int _tmain(int argc, _TCHAR* argv[]) • {int x=7; • int &y=x; • cout<<"\n\tx :"<<x<<endl; • cout<<"\n\ty :"<<y<<endl; • x++; • cout<<"\n\tx :"<<x<<endl; • cout<<"\n\ty :"<<y<<endl; • y++; • cout<<"\n\tx :"<<x<<endl; • cout<<"\n\ty :"<<y<<endl; • getchar(); getchar(); • return 0; • } Burada x ve y değişkenleri aynı adresteki değeri tutmaktadırlar. Yani adres ataması yapıldıktan sonra birinde olan değişiklik diğerinde de aynen olur.

  8. Fonksiyonun prototipinde ve fonksiyon başlığında & işaretini kullanıyoruz • #include"stdafx.h" • #include<iostream> • usingnamespace std; • void degerFonksiyon(int); • void referansFonksiyon(int &); • int _tmain(int argc, _TCHAR* argv[]) • { • int a=5; • int b=10; • degerFonksiyon(a); • referansFonksiyon(b); • cout<<"\na :"<<a<<endl; • cout<<"\nb :"<<b<<endl; • getchar(); getchar(); • return 0; • } • void degerFonksiyon(int x) • { • x*=x; • } • void referansFonksiyon(int &y) • { • y*=y; • }

  9. C++ Örneği(Float) • #include"stdafx.h" • #include<iostream> • usingnamespacestd; • int _tmain(intargc, _TCHAR* argv[]) • { • float i,j; • float *p; • i=j=11.93; • p=&j; • *p=99.11; • cout<<"i = "<<i<<endl<<"j= "<<j<<endl<<"*p="<<*p; • getchar(); • return 0; • }

  10. İşaretçilerin Fonksiyonlarda Kullanımı Standart parametre gönderimi • #include"stdafx.h" • #include<iostream> • usingnamespacestd; • voiddegistir(int s) • { • s=100; • } • int _tmain(intargc, _TCHAR* argv[]) • { • int a=22; • degistir(a); • cout<<"a = "<<a<<endl ; • getchar(); • return 0; • }

  11. İşaretçi Parametre Gönderimi • #include"stdafx.h" • #include<iostream> • usingnamespacestd; • voiddegistir(int *s) • { • *s=100; • } • int _tmain(intargc, _TCHAR* argv[]) • { • int a=22; • degistir(&a); • cout<<"a = "<<a<<endl ; • getchar(); • return 0; • }

More Related