YOUR C LEARNING COMPANION

Kahan se padhein?

Learning path
C ki buniyadChapter 15 of 73

Comments: C mein intent samjhana

Comment syntax, translation, limits aur decision document karne aur behavior change karne ka difference samjhein.

5 min readFoundationsC17 baseline
Offline reading
Is chapter mein8 sections
0% through this chapter

Comments source padhne wale logon ke liye explanation dete hain. Yeh bata sakte hain ki koi choice kyun hui ya operation kya assume karta hai. Inke syntax rules bhi hain: comment kahan shuru, kahan end aur aas-paas ke text par kya effect hota hai, yeh samjhenge.

1. C mein do familiar comment forms hain

C17 · illustrative fragment
/* A block comment can span
   more than one source line. */
int count = 3;
// One more book has just arrived.
count += 1;

Block comment /* se shuru hota hai aur first following */ par end hota hai. Line comment // se relevant source line ke end tak chalta hai, line splicing ke baad. C99 se line comments available hain, hamare C17 baseline mein bhi. Block comment ek line mein bhi ho sakta hai.

Increment code karta hai. Comment reason explain karta hai. Comment “ek aur aaya” kahe aur code one subtract kare, toh comment operation nahi badalta. Comments ko code aur intended task dono se match karke check karein.

2. Comments replace hoti hain, bas chipkakar delete nahi

Translation mein har comment space se replace hota hai. Isse int/**/count mein separation rehta hai. Replacement space ke bina delete karne par intcount alag token banega. Comment executed operation add nahi karta, lekin uski position token separation affect kar sakti hai.

Comment syntax lexical context ke according recognize hoti hai. String literal ke andar // line comment start nahi karta; string mein /* block comment start nahi karta. Yeh URLs aur source punctuation wale text mein useful distinction hai.

Complete C17 program
#include <stdio.h>

int main(void) {
    puts("/* this is text */");
    return 0;
}

Output successful ho toh program apparent comment markers ko ordinary text ki tarah likhta hai, phir newline. Quotation marks string literal establish karti hain; markers uske data ka part hain. Sirf do characters search karke comments par reason na karein; context bhi dekhein.

3. Block comments nest nahi hoti

Block comments nest nahi hote. Andar ka /* naya level nahi banata; first */ comment end karta hai. Existing source ko block comment mein wrap karte waqt care karein. Existing closing marker use jaldi end karke unwanted source expose kar sakta hai.

Temporarily source exclude karne ke liye editor ka line-comment tool carefully, ya rules samajhne par suitable conditional preprocessing technique use karein. Dono deliberate code change aur review ka substitute nahi. Arbitrary pasted region ko “commented out” kehna automatically safe nahi banata.

4. Physical aur logical lines alag ho sakti hain

Comments replace karne se pehle C immediately followed backslash-newline ko join karti hai. Isliye // comment next physical line tak continue ho sakta hai. Line comment ke end par aisa backslash avoid karein. Next line ki indentation joining rule cancel nahi karti.

Aur gehra samjhein: comments remove karna lexical task hai

Comment-removal tool ko string aur character literals, escapes, line splicing aur token separation account karna chahiye. Naive text replacement program badal sakti hai, chahe author sirf reformat karna chahta ho. Isliye language-aware tooling useful hai.

5. Reason aur boundary document karein

Useful comment decision explain karta hai: measurement ki unit, allowed range ya steps ke order ka reason. Names se ordinary operations readable banayein. Comment mein aisa reason ya assumption dein jo reader code se easily na jaan sake.

Comments stale ho sakti hain. Code change karte waqt explanation, assumptions aur accompanying examples bhi check karein. “Input hamesha valid hai” jaisi reassuring line validation nahi. Appropriate boundary par contract establish karein ya failure handle karein. Clear names aur coherent small functions se comments ko kam explanatory repair karni padti hai.

Thoda sochkar dekhein

Source mein puts("// note"); hai. Kya // us call ka output rokta hai?

Explanation padhein

Nahi. Yeh string literal ke andar ordinary data hai. Suitable complete program mein successful call text aur newline likhti hai.

Primary references aur aage ki reading

Aage badhne se pehle

  • Comments intent explain karte hain; ordinary executed operations nahi bante.
  • Comment replacement, literals aur line splicing source interpretation affect karte hain.
  • Useful comment reason ya contract batata hai aur code se consistent rehna chahiye.
In ideas ko alag rakhein
Comment marker / Literal data
Same slash characters quotation marks ke andar string data ho sakte hain; woh comment shuru nahi karte.
Apne words mein samjhaayein

Comment characters carelessly delete karne se token boundaries ya exposed source kyun badal sakte hain?

Optional: bolkar samjhein ya note rakhein. Tayyar hon toh aage badh sakte hain.

Apni understanding check karein

Optional hai. Answers save ya send nahi hote; chapter kabhi lock nahi hota.

Literals ke bahar int/**/count; se count declare kaise ho sakta hai?
Har choice ki explanation padhein
  1. Comment whitespace se replace hota hai, jo tokens separate karta hai.

    ✓ Sahi reasoning. Yeh int aur count ko ek identifier mein nahi jodta.

  2. Comment declaration se pehle execute hota hai.

    Comments translation mein handle hote hain, runtime statements ki tarah execute nahi.

  3. Characters identifier intcount ban jaate hain.

    Comment replacement tokens concatenate karne ke bajay separation deta hai.

C17

Pehle edition ka quick reference

Yeh compact reference existing links aur saved passages ke liye retained hai. Full context ke liye upar ki expanded lesson padhein.

Comments source code mein non-executable annotations hote hain, jo readability aur maintainability improve karne ke liye intended hote hain. C language do types ke comments support karti hai:

  • Multi-line Comments: /* aur */ ke beech mein enclosed hote hain. In delimiters ke beech mein sab kuch compiler ignore kar deta hai.
C17 · illustrative fragment
/* Yeh ek multi-line comment hai.
   Yeh multiple lines tak fail sakta hai. */
  • Single-line Comments: C99 mein introduce hue, // se start hote hain aur line ke end tak continue karte hain.
C17 · illustrative fragment
// Yeh ek single-line comment hai.

Best Practices:

  • Complex logic, assumptions, ya code sections ke purpose ko explain karne ke liye comments use karein.
  • Redundant comments avoid karein jo obvious code ko dobara restate karte hain.
  • Aise comments prefer karein jo "how" ke bajaye "why" explain karein.
  • Comments ko clear code ka substitute na banayein.

Example:

C17 · illustrative fragment
#include <stdio.h>

// Do numbers ka sum print karo
int main(void) {
    int a = 5, b = 10;
    /* Sum calculate aur print karo */
    printf("Sum: %d\n", a + b);
    return 0;
}

Note: Block comments nest nahi hote: pehla */ comment ko end karta hai. Andar ka /* ordinary comment text hai. Nested comment ki koshish unintended source text chhod sakti hai, diagnostics la sakti hai ya program badal sakti hai; yeh supported commenting technique nahi hai.

Agla idea padhne ke liye tayyar?

Mark this chapter as read whenever you feel ready.

CHAPTER 15 / 73

Is chapter mein

Comments: C mein intent samjhana

Search all 73 chapters in both languages.EN + HG

Try “pointer”, “why int”, or “undefined behavior”.

Concepts connect. Follow your curiosity.↑ ↓ to explore · Enter to open
MAKE YOURSELF COMFORTABLE

Your reading space

Appearance

A clear canvas with balanced contrast.

Text size

100%
AA

Reading tools

Your data stays in this browser

Export a backup before changing browsers or replacing an older version of the reader.

YOUR PERSONAL MARGINS

My notebook

Saved on this device
A LITTLE CLARITY

The glossary

A starting meaning, then a chapter to go deeper.

A QUICK DEFINITION

A little clarity

Read the full explanation →

A thought worth keeping