28 views

المؤشرات Pointers

Filed Under (Programming) by Sophto_92 on 26-04-2009

Tagged Under : , ,

الموضوع الاصلي من هنا : knol.google.com

السلام عليكم ،،،

1. المؤشرات Pointers

المؤشرات هي عبارة عن نوع خاص من المتغيرات variables، تقوم بتخزين عنوان يشير للمتغير الموجود في الذاكرة العشوائية RAM او بتخزين القيمة الفعلية. هناك علامتين يتم استخدامهم في عالم المؤشرات، الاولى & والثانية *.
& : تعني اننا نريد العنوان الخاص بالمتغير في الذاكرة.
* : تستخدم عند تعريف متغير من نوع مؤشر Pointer.


لو قمنا بتعريف متغير x من نوع int كالتالي :

int x = 9;

الآن، عندما نريد استخدام هذا المتغير في الكود البرمجي، فالذي نقوم به هو فقط الإشارة للمتغير x ومن المنطقي أنه سيحمل القيمة 9 وليس العنوان الخاص به 5 في الذاكرة  كما هو موضح في الصورة اعلاه. لكن لفترض اننا نريد العنوان الخاص بهذا المتغير في الذاكرة لسبب ما. في هذه الحالة نقوم بالتالي:

int y = &x;

القيمة المخزنة في المتغير y هي بالطبع العنوان الخاص بالمتغير x في الذاكرة وهي 5. لتعريف متغير كمؤشر نقوم بالتالي:

int *k;

ماقمنا به هو تعريف متغير k كمؤشر من نوع int. وعندما نريد استخدام هذا المؤشر فهناك امرين مهمين:

  • استخدام اسم المتغير k يعني اننا نريد فقط العنوان او المؤشر للخانة الخاصة بهذا المتغير في الذاكرة.
  • استخدام المتغير k* يعني اننا نريد القيمة الفعلية وليس العنوان الخاص به في الذاكرة.

مثال بسيط على اخر نقطتين :

int *z = 0;

  • استخدام z يعني 4 ، كما هو موضح في الصورة اعلاه.
  • استخدام z* يعني 0 ، كما هو موضخ في الصورة اعلاه.

2. استخدام المؤشرات Pointers

للمؤشرات استخدامات كثيرة جداً في لغات البرمجة، من اهم هذه الاستخدامات الارسال عن طريق عنوان (Pass By Reference) نوضحه بمثال:

1. #include<stdio.h>

2. void test1(int m, int n)               //تعريف لدالة تستقبل متغيرين

3. {

4. m=5;

5. n=24;

6. }

7. void test2(int *m, int *n)             //تعريف لدالة تستقبل مؤشر لمتغيرين

8. {

9. *m=5;                                             //تخزين الرقم 5 كقيمة فعلية داخل المتغير

10. *n=24;                                          //تخزين الرقم 24 كقيمة فعلية داخل المتغير

11. }

12. int main(void)

13. {

14. int a=10, b=16;

15. printf(”a=%d, b=%d\n”,a,b);

16. test1(a,b);

17. printf(”a=%d, b=%d\n”,a,b);

18. test2(&a &b);

19. printf(”a=%d, b=%d\n” , a , b);

20. return 0;

}

توضيح للكود اعلاه:

  • في السطر (16) مناداة الدالة (test1(10,16 وسوف تقوم هذه الدالة في السطرين (4) و (5) بتغير القيمة الى 5 و 24. لكن كما تعلم ان المتغيرين m و n هما خاصين فقط بالدالة test1 وليس لهما اي تأثير خارج هذه الدالة. لذلك عند الوصول للسطر (17) تقوم دالة الطباعة printf بطباعة الرقمين 10 و 16 وليس 5 و 24.
  • لكن عند السطر (18) يتم مناداة (test2(&10,&16 وسوف تقوم بإرسال متغيرين يحملان العنوان في الذاكرة لكل من a  و b للدالة test2. كما ترى في السطر(7) فالدالة تتوقع مؤشرين كما فعلنا في السطر(18)، وعند الوصول للسطر (9) و (10) نقوم بتغير القيم لكل من a و b الى 5 و 24 بدلاً من القيمة السابقة 10 و 16. استطعنا فعل ذلك بسبب ارسال عناوين الذاكرة الخاصة بـa و b بدلا من ارسال القيم الفعلية لهما كما في test1. وعند الوصول لدالة الطباعة في السطر(19) printf تقوم بالتأكيد بطبع 5 و 24 على التوالي.

مثال اخر يوضح قوة استخدام المؤشرات Pointers:

1. #include <stdio.h>

2. main()

3. {

4. int i1, i2, *p1, *p2;

5. i1 = 5;

6. p1 = &i1;

7. i2 = *p1 / 2 + 10;

8. p2 = p1;

9. printf(”i1=%d, i2=%d, *p1=%d, *p2=%d\n”, i1, i2, *p1, *p2);

}

توضيح للكود اعلاه:

  • في السطر (4) قمنا بتعريف متغيرين عاديين ومتغيرين كمؤشر.
  • في السطر (6) قمنا بتخزين عنوان الذاكرة الخاص بـil في المؤشر p1. وفي هذه الحالة اصبح المتغير p1 يشير الى المتغير il.
  • في السطر (7) قمنا بإستخراج القيمة الفعلية في p1 بإستخدام p1* وهي 5. ثم قمنا بعملية حسابية بسيطة وتخزينها في المتغير i2.
  • في السطر (8) قمنا بتخزين عنوان الذاكرة الخاص بـp1 وهوا الذي يشير الى il في المؤشر p2.
  • في السطر (9) بإستخدام دالة الطباعة، النتائج سوف تكون كالتالي:

i1 = 5, i2= 12, *p1= 5, p2= 5

للتكملة فقط، تجدر الإشارة ان الـArrays في لغة C تستخدم المؤشرات، مثال :

1. int array[5] = {1,3,6,7,5};

2. int x = array[0];

3. int y = *(++array);

توضيح للكود اعلاه:

  • في السطر (1) قمنا بتعريف Array تحتوي على خمسة عناصر.
  • في السطر (2) قمنا بتعريف متغير x يحتوي على القيمة الموجودة في [array[0  وهي 1 في هذه الحالة. تعتبر هذه الطريقة الاولى والمعروفة للتنقل بين العناصر في الـArrays باستخدام رقم بين القوسين يدل على ترتيب العنصر في الـ Arrays.
  • في السطر (3)  array++ قمنا بزيادة المؤشر اللذي كان يشير لاول عنصر في الـArray الى الأشارة الى العنصر الثاني في الـArray. ثم عن طريق استخدام العلامة * الخاصة بإستخراج القيمة الفعلية من المؤشر، تم تخزين القيمة 3 في المتغير y.

٣- فيديو توضيحي

فيديو يوضح بطريقة مبسطة المقصود بالمؤشرات وكيفية استخدامها، مفيد جداً.

Everything u need to know about pointers

المراجع:

bookmark bookmark bookmark bookmark bookmark

40 views

هل جهازك الماك مصاب

Filed Under (Mac) by Sophto_92 on 24-04-2009

Tagged Under : ,

السلام عليكم،،،

اكيد سمعتو عن التروجان اللي انتشر من بداية شهر يناير تقريبا في اجهزة الماك للي حملو برنامج iWork ‘09 من مواقع التورنت او من اي مصدر اخر غير الديفيدي اللي يجي من آبل…عموما باي طريقة كانت حملت فيها البرنامج غير الطريقة الشرعية، انصحك انك تتبع الخطوات وتشيك على جهازك عشان تتطمن :)

الطريقة اليدوية:

شغل برنامج Terminal.app الموجود في مجلد Utilities في Applications… اللي راح نسويه اننا نبحث بعدة طرق عن كلمة iWorkServices لانها الكلمة الدلالية لهذا التروجان..

١- البحث في البرامج الشغالة Processes

sudo ps aux |grep -i iworkserv |grep -v “grep”

راح يقوم هذا الامر بالبحث في كل الـProcesses عن iworkserv ، اذا رجع لك الامر اي  شي يعني جهازك مصاب.

٢- البحث في الملفات المفتوحة

sudo lsof -i -P|grep -i iworkserv

راح يقوم هذا الامر بالبحث عن اي ملف تم فتحة عن طريق Process بالاسم iworkserv ،  اذا رجع لك الامر اي  شي يعني جهازك مصاب.

٣- البحث في ملفات جهازك عن التروجان

sudo find / -iname “iworkserv*” -print

راح يقوم هذا الامر بالحث في كل الملفات في جهازك في اي مكان في الهارديسك عن اي ملف يبدا بالاسم iworkserv ،  اذا رجع لك الامر اي  شي يعني جهازك مصاب.

الحل الاخر عن طريق البرامج:

في برنامج قامت به SecureMac مجاني بفحص جهازك اذا كان يحتوي على هذا التروجان او لا.. واذا حصله عندك يقوم بحذفه من الجهاز

اخيراً:

انا قمت بعمل الخطوات اليدوية كلها والحمد لله جهازي كان نظيف مايحتاج انزل البرنامج، لكن انا انصح انه تقوم بعمل الخطوات اليدوية اولا واذا حصلت شي في جهازك نزل البرنامج وسوي سكان scan للجهاز وخليه يحذف لك التروجان.

المصدر

bookmark bookmark bookmark bookmark bookmark

45 views

استخدام برنامج MS Visual SourceSafe 2005

Filed Under (Project Management) by Sophto_92 on 11-04-2009

Tagged Under : ,

السلام عليكم،،،

وبعد غياب طويل عدنا مره ثانية … وان شاء الله اقدم المفيد لكم دائما..

اليوم راح يكون فيديو عن كيفية استخدام Microsoft Visual SourceSafe 200 في البروجكتات(المشاريع).. الصغيرة كانت او المتوسطة…

اتركم مع الفيديو “لمشاهدة افضل الرجاء تكبير العرض”

:للإستزاده الرجاء البحث البحث البحث

www.google.com وابحث عن MS Visual SourceSafe او بشكل اعمSVN

تحياتي

bookmark bookmark bookmark bookmark bookmark

388 views

Mac OS X Programming - Part 1

Filed Under (Cocoa Programming, Mac) by Sophto_92 on 15-11-2008

Tagged Under : , ,

Note: This topic written in English since it was orginally intended to be published in Shuffle Magazine, but I changed my mind for now at least.

Programming for Mac OS X is unlike programming for any other platform. I have been programming in .Net framework for Windows and Java SE for almost three years, but never felt what I feel when programming for Mac OS X especially using Cocoa framework. I think this feeling is because; first I love my Mac. Second, what Cocoa framework can provide you without writing any single line of code. So, what is Cocoa framework?.

Cocoa is a collection of related classes that can provide you with all what you want in developing project from small to very large ones. Cocoa framework consists of many sub-frameworks; like the Foundation framework, Application Kit and many others. Cocoa power can be seen in almost all applications developed for Leopard, you will notice that all of them have many common things. They all support the built-in dictionary, they look the same and feel the same, etc. This kind of consistency in Mac OS X application increase the usability and enhance understandability of the system from novice users to experts ones.

Programming for Mac OS X is mostly done using Objective-C language. However, to support universality and not enforcing everyone to learn Objective-C language; Java , Ruby and Python programmers can write their applications for Mac OS X on top of Cocoa framework and take full advantage of this powerful collection of classes,i.e. Cocoa. In this series of articles I will focus on Objective-C language and how to use it to write very simple program in no time.

Read More »

bookmark bookmark bookmark bookmark bookmark

112 views

Challenges Faced by Search Engines

Filed Under (Drasty, General) by Sophto_92 on 07-11-2008

Tagged Under : , , ,

The topic about search engines is very very interesting and AMAZING to me, imagine crawling through the whole Internet indexing its contents .. that is just CRAZY man and it really requires geniuses to make it successful like google for example. To get the feeling of how awesome designing search engines, take a look at this document about Google. However, designing search engines is faced by many challenges here is some of them:

  • The Size of the Web: as you know the Web is growing very fast. It is estimated no to be around 23.91 billion indexed pages.
  • Currency: this one concern with websites get updated very frequently which means search engines must visit them periodically.
  • Relevancy: one of the big challenges is wether the search engine will provide you with what you really want when giving a keyword or it will give you something called false-positive.
  • Dynamically generated Web-sites: sites that are generated from databases like dictionary site and so on.
  • They can be tricked: yes they can be tricked, by giving false information in the metadata section of the webpage and garbage information in the body. This act will of course push down many websites that are relevant to your keywords. 
  • Secure webpages: of course search engines will not be able to index them since the are secure. However, some websites they don’t like to be indexed and this is where a lot of problems occurs. These websites might be governmental ones.
This is just a simple and brief points about the challenges that are being faced by search engines.
Note: This topic is a summery for one of the lectures in SWE 444 - Web development course. It is also for supporting Drasty idea.
Regards,,

bookmark bookmark bookmark bookmark bookmark

310 views

Bookmarklet for Untiny

Filed Under (General) by Sophto_92 on 05-10-2008

Tagged Under :

hello folks :) ,, 

I think everyone heard about what Saleh Alzaid programmed about one month ago, Untiny. It is a great service really, and he also programmed a great firefox extension. What I present to you today isn’t a new thing, It is just a modification for an existing bookmarklet that do the same thing but for another service. So, lets see a small video about how it works :D .


Bookmarklet for Untiny from Mohannad Shahat on Vimeo.


you will need this after the video untiny .

 

Nice ha? :)

c u..

bookmark bookmark bookmark bookmark bookmark

75 views

Apple Event “Let’s Rock”

Filed Under (Mac) by Sophto_92 on 10-09-2008

Hi folks,,

Here is some of the major things that came out from Apple “Let’s Rock” event yesterday..

1. iTunes 8

2. New iPod nano

3. New iPod Touch

4. iPod Touch & iPhone get 2.1 software update

5. Update iPod Shuffle

6. Update iPod Classic

 

finally, you can watch Steve Jobs keynote stream from here

 

Or download it using iTunes from here

Regards,

 

 

 

bookmark bookmark bookmark bookmark bookmark

195 views

Save picture from Flickr

Filed Under (General) by Sophto_92 on 06-09-2008

Tagged Under : ,

Today, I will tell you how to save pictures that are protected from downloading in Flickr.

So, here we go:

1. View the page source in your browser

2. do a search the in source (Ctrl+F)

3. type in the search field: class=”photoImgDiv”

4. You will see after that something that begin with http://… which will be the picture link

5. copy the link to the browser and save the picture from there

thats it…

Regards,,

bookmark bookmark bookmark bookmark bookmark

92 views

Plex for Mac

Filed Under (Applications, Mac) by Sophto_92 on 06-09-2008

Tagged Under : , ,

السلام عليكم…

اليوم جايب لكم برنامج لئطه الصراحه يسحرك بجماله والابداع فيه… الصراحه البرنامج افضل بكثييير من الـ

 اللي يجي مع الماكFront Row  

وهذي بعض الصور

imgMov2001-w900.jpg

رابط التحميل من هنا

تحياتي

bookmark bookmark bookmark bookmark bookmark

329 views

SQL Injection Attacks

Filed Under (Computer Security) by Sophto_92 on 25-08-2008

Tagged Under : , ,


For those who are interested in SQL Injection Attacks and how to protect

their web application from it. Try reading this series of tutorials. 

http://st-curriculum.oracle.com/tutorial/SQLInjection/index.htm

Read More »

bookmark bookmark bookmark bookmark bookmark