Skip to content · ⁨דלג לתוכן⁩

Pointers: &, *, and pass-by-pointer · ⁨איורים: &, *, ומעבר באמצעות איור⁩

English

A problem from last lesson

  • Last lesson, a function got a copy of your number. Changing the copy did not change the original.
  • C copies every argument you pass to a function. So a normal function cannot change your variable.
  • To change it, the function needs the variable's address — where it lives in memory.

עברית

בעיה מהשיעור הקודם

  • בשיעור הקודם, פונקציה קיבלה עתיקה של המספר שלך. שינוי העתיקה לא שינה את המקורי.
  • C מעתיקה כל ארגומנט שמעביר לפונקציה. לכן פונקציה רגילה לא יכולה לשנות משתנה שלך.
  • כדי לשנות אותו, הפונקציה צריכה את כתובת המשתנה — היכן שהוא נמצא בזיכרון.

x מכיל 5 בכתובת 0x100; הפוינטר p מכיל 0x100, לכן *p מגיע ל-5

Handout · ⁨חומר עזר⁩

Log in or create account · ⁨היכנס או צור חשבון⁩

IGCSE, A-Level & AP