المؤشرات
المؤشرات
تحتوي Go على مؤشرات. يحتفظ المؤشر بعنوان قيمة في الذاكرة.
النوع *T هو مؤشر إلى قيمة من النوع T. قيمته الصفرية هي nil.
var p *int
يولّد العامل & مؤشرًا إلى المعامل الذي يعمل عليه.
i := 42 p = &i
يدلّ العامل * على القيمة التي يشير إليها المؤشر.
fmt.Println(*p) // read i through the pointer p *p = 21 // set i through the pointer p
يُعرف هذا باسم "فكّ الإشارة" أو "الوصول غير المباشر".
بخلاف C، لا تحتوي Go على عمليات حسابية على المؤشرات.
النص الأصلي بالإنجليزية
Pointers
Go has pointers. A pointer holds the memory address of a value.
The type *T is a pointer to a T value. Its zero value is nil.
var p *int
The & operator generates a pointer to its operand.
i := 42 p = &i
The * operator denotes the pointer's underlying value.
fmt.Println(*p) // read i through the pointer p *p = 21 // set i through the pointer p
This is known as "dereferencing" or "indirecting".
Unlike C, Go has no pointer arithmetic.
هذا الدرس للقراءة فقط؛ جرّب المثال في الدرس التالي.