C में Comments
In this page:
// single-line comment
/* multi-line
comment */
Single-Line Comments
एक single-line comment // से शुरू होता है और compiler को उस point से line के अंत तक सब कुछ ignore करने को कहता है -- आस-पास के code को बिना disturb किए किसी specific statement के बगल में एक quick note के लिए handy।
उदाहरण: Single-Line Comments
#include <stdio.h>
int main() {
// This line explains the printf below
printf("Hello");
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Multi-Line Comments
एक multi-line comment /* से शुरू होता है और */ पर खत्म होता है, और बीच की हर चीज़ ignore हो जाती है चाहे यह कितनी भी lines तक फैली हो -- logic के पूरे block को explain करने या एक साथ कई lines को temporarily disable करने के लिए useful।
उदाहरण: Multi-Line Comments
#include <stdio.h>
int main() {
/* This comment
spans multiple lines */
printf("Hello");
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Code Document करना
अच्छे comments यह explain करते हैं कि code का कोई हिस्सा *क्यों* exist करता है या जिस तरह काम करता है वैसे क्यों करता है, सिर्फ line-by-line *क्या* करता है यह नहीं -- code खुद पहले ही दिखा देता है क्या हो रहा है, लेकिन एक tricky decision के पीछे की reasoning सिर्फ आप जानते हैं।
उदाहरण: Documenting Code
#include <stdio.h>
int main() {
// Using 1024 because memory is measured in kibibytes here
int kilobyte = 1024;
printf("%d", kilobyte);
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Code को Comment Out करना
code के किसी block को delete करने की बजाय comment markers में wrap करना आपको debug करते हुए इसे temporarily disable करने देता है, ताकि आप उस code को हमेशा के लिए खोए बिना test कर सकें कि क्या कोई specific section किसी bug का source है।
उदाहरण: Commenting Out Code
#include <stdio.h>
int main() {
printf("Active code");
// printf("Disabled while debugging");
return 0;
}
Login to try C/C++/Java/PHP code in the editor
अच्छी Comment Habits
बहुत लंबे या obvious code को दोबारा बताने वाले comments clarity की बजाय noise add करते हैं, और आस-पास का code बदलने के बाद unchanged छोड़े गए comments actively misleading बन जाते हैं -- stale comments को fix करने वाले एक bug की तरह treat करें।
उदाहरण: Good Comment Habits
#include <stdio.h>
int main() {
int x = 5; // avoid: "sets x to 5" -- explain reasoning instead
printf("%d", x);
return 0;
}
Login to try C/C++/Java/PHP code in the editor
/* */comments को nest करना, जहाँ पहला*/पूरे comment को खत्म कर देता है और बाकी बचा हुआ broken code बन जाता है।- strict C89 compiler mode में
//comments इस्तेमाल करना, जहाँ सिर्फ/* */allowed है। - outdated commented-out code को आस-पास छोड़ देना जो अब program actually क्या करता है इससे match नहीं करता।
Chapter Quiz — Complete all 21 topics to unlock
0/21 topics done
Complete these topics first:
- C Introduction
- C History & Features
- C Environment Setup
- C First Program
- C Syntax & Structure
- C Statements
- C Comments
- C Keywords & Identifiers
- C Data Types
- C Character Data Type
- C Numeric Data Types
- C Decimal (Floating-Point) Numbers
- C sizeof Operator
- C Extended Data Types
- C Type Conversion
- C Booleans
- C Variables
- C Changing Variable Values
- C Multiple Variables
- C Constants
- C Fixed-Width Integers