الطباعة باستخدام std.debug.print
اعرضوا النص على الشاشة ونسّقوا القيم
الطباعة باستخدام std.debug.print درس مجاني في Zig Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Zig Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Zig Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Your Window into the Program
Printing text is how you see what your code is doing. Zig's quickest way to do that is std.debug.print. 🖨️
Reaching Into std
The dots in std.debug.print are a path: the std module contains debug, which contains the print function you are calling.
const std = @import("std");
std.debug.print("Hello\n", .{});Two Arguments, Always
print always takes two things: a format string and a tuple of values to fill into it. Even with no values, you pass an empty tuple.
The Empty Argument Tuple
That .{} is an empty tuple. When your text has no placeholders, you still supply it so the function signature is satisfied.
std.debug.print("No values here\n", .{});Placeholders Use Braces
Inside the format string, {} marks a spot to drop in a value. Each placeholder pulls the next item from your argument tuple in order.
std.debug.print("Score: {}\n", .{42});Passing Multiple Values
List several values in the tuple and they fill the placeholders left to right, making it easy to combine data in one line.
std.debug.print("{} plus {} is {}\n", .{2, 3, 5});Format Specifiers
Add a letter inside the braces to control output. For example {s} prints a string slice and {d} forces decimal integer formatting.
std.debug.print("Name: {s}\n", .{"Ada"});Newlines Are Manual
print does not add line breaks for you. Include the \n escape yourself whenever you want output to move to the next line.
It Writes to stderr
One key detail: std.debug.print sends text to stderr, the error stream. That is fine for learning and quick debugging output.
For Real Output, Use stdout
Serious programs print results to stdout via a writer. But debug.print stays the friendliest choice while you are exploring.
No Allocator Needed
A nice perk: std.debug.print needs no allocator. You can call it anywhere, even before you set up memory management.
Quick Check
You write std.debug.print("Hi\n", .{}). What is the role of the .{} part?
Recap
Use std.debug.print with a format string and an argument tuple. Fill {} placeholders, add \n yourself, and remember it writes to stderr. 🎯
الأسئلة الشائعة
هل درس «الطباعة باستخدام std.debug.print» مجاني؟
نعم — نص درس «الطباعة باستخدام std.debug.print» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Zig Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Zig Academy 4 دروس في المجموع.
ماذا ستتعلم في «الطباعة باستخدام std.debug.print»؟
اعرضوا النص على الشاشة ونسّقوا القيم تتمرن على Zig Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Zig Academy؟
لا تُشترط خبرة سابقة. Zig Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «الطباعة باستخدام std.debug.print»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Zig Academy هذا؟
نعم. كل درس في Zig Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- تثبيت Zig على أي منصة
- دالة main الأولى
- الطباعة باستخدام std.debug.print
- الترجمة والتشغيل في خطوة واحدة