C ko padhna: tokens, expressions aur statements
C ki line ke small language units pehchanein aur unhe declarations, expressions aur statements se jodein.
Is chapter mein8 sections
Poora program padhne se pehle uske chhote parts pehchaanein. C written characters ko tokens mein group karti hai, phir tokens se declarations, expressions aur statements banti hain. Isi tarah familiar punctuation ka precise meaning banta hai.
1. Tokens language ke units hain
int count = 3;
int total = count + 1;Token preprocessing ke baad C source ka recognised piece hai. total jaisa poora naam ek token hai. == bhi ek token hai, chahe do characters hain. int total = count + 1; mein har naam, constant aur punctuator ka alag job hai.
| C17 category | Examples | Role |
|---|---|---|
| Keyword | int, if, return | Grammatical roles wale reserved spellings |
| Identifier | count, total | Entity ka naam |
| Constant | 1, 2.5, 'A' | Type aur value wala constant token |
| String literal | "hello" | Quoted character sequence, separate token category |
| Punctuator | ;, {, +, == | Structural symbols; kai operators bhi hain |
“Operator” role batata hai, C17 list ki sixth lexical category nahi. + punctuator addition operator ka role nibha sakta hai. Preprocessing ki apni token rules hain, including preprocessing numbers; har intermediate token ko already-valid final C constant assume na karein.
2. Names rules ke andar choose hote hain
First portable names ke liye basic letters, digits aur underscores use karke letter se shuru karein. meal_count jaisa descriptive naam choose karein. C aur library kuch names reserve karti hain; sirf keywords avoid karna poora rule nahi. Wider characters ke version-specific requirements hain.
int score = 2;
int Score = 3;C case distinguish karti hai, isliye yeh do objects ke do names hain. Example rule dikhata hai; names sirf capitalization se different rakhne ki recommendation nahi. main hosted startup ka special function name hai, lekin C keyword nahi. Familiar name pehchaanne se lexical category automatically nahi pata chalti.
3. Expression computation mein participate karti hai
Expression value compute, object ya function refer, ya side effects cause kar sakta hai. count + 1 value compute karta hai. count = 4 object change karta hai. Function call bhi expression hai. Kuch expressions ka type void hai aur ordinary result value nahi milti.
Symbol ko surrounding construct mein padhein. * expression mein multiplication kar sakta hai ya pointer declare karne mein help kar sakta hai. Parentheses expression group ya function call mark kar sakti hain. Shape pehchaanna shuruaat hai; context uska job batata hai.
4. Statements aur declarations alag block items hain
Expression ke baad semicolon se expression statement ban sakti hai: count = count + 1;. int count = 3; jaisi declaration ka role alag hai. C function blocks mein declarations aur statements dono allowed hain. Semicolon common hone se constructs same nahi ho jaate.
Compound statement braces se block items group karti hai. Braces initialization jaise other contexts mein bhi aati hain; “har brace function block start karti hai” reliable rule nahi. #include <stdio.h> preprocessing directive ka role phir alag hai; yeh ordinary statement nahi jiske end par semicolon add karna ho.
5. Formatting humans ki help karti hai, lekin kuch whitespace matter karti hai
Statement kai lines mein aa sakti hai aur ek line par kai statements ho sakti hain. Indentation person ko structure dikhati hai. Spaces tokens separate bhi karti hain: int count aur intcount different source hain. Literal ke andar spaces stored text ka part ho sakti hain.
Newlines preprocessing directives terminate karti hain, aur comment replacement aur line splicing translation rules se hote hain. Isliye formatting na “poori meaningful” hai na “poori irrelevant.” Consistent indentation aur spacing learner ko grammar-defined structure dekhne mein help karte hain.
int total = count + 1; mein total keyword hai? Kya poori line expression statement hai?
Explanation padhein
Dono ka answer nahi. total identifier hai. Poori line initializer wali declaration hai; us initializer mein count + 1 expression hai.
Primary references aur aage ki reading
- WG14 N1570 — public C11 committee draft: Sections 5.1.1.2, 6.4, 6.5, 6.7, and 6.8 is C17-baseline explanation ke core rules deti hain. Yeh public draft hai, final ISO publication nahi.
Aage badhne se pehle
- C tokens recognise karke grammar ke according combine karti hai.
- Expressions, declarations aur statements common punctuation ke bawajood different jobs karte hain.
- Whitespace tokens separate kar sakti hai; literal ke spaces data bhi ho sakte hain.
In ideas ko alag rakhein
- Token category / Operator role
- + jaisa punctuator operator ka role le sakta hai; lexical category aur grammatical job alag descriptions hain.
int total = count + 1; ko poora expression kahe bina uske parts kaise alag karenge?
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.
Har choice ki explanation padhein
- Expressions mein = assignment aur == equality comparison karta hai.
✓ Sahi reasoning. Unke expression roles alag hain. = token initialization syntax mein bhi aata hai; wahan woh assignment expression nahi hota.
- Whitespace decide karta hai ki dono assignment mean karte hain.
Whitespace in operators ko interchangeable nahi banata.
- Compiler programmer ke intention se meaning choose karta hai.
Language ke token aur expression rules unke roles decide karte hain.
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.
C source code tokens ki ek sequence se bana hota hai, jo language ki sabse chhoti meaningful units hoti hain. Primary token types yeh hain:
- Keywords: Reserved words, jaise
int,ifaurreturn. - Identifiers: Objects, functions, types aur doosri entities ke naam.
- Constants: Integer, floating, enumeration aur character constants, jaise
42,3.14aur'A'. - String literals:
"hello"jaise quoted character sequences; yeh alag token category hai. - Punctuators:
;,{,},+,*aur&&jaise symbols. Kai punctuators operators ka kaam karte hain; “operator” C17 mein separate lexical token category nahi hai.
Whitespace normally tokens ko separate karta hai aur translation mein har comment ek space se replace hota hai. Literals ke andar whitespace data hai; newline preprocessing directive ko end karti hai aur kuch macro definitions mein whitespace important hoti hai. Saare spaces ya comments delete karne se program unchanged rahega, aisa assume na karein.
Agla idea padhne ke liye tayyar?
Mark this chapter as read whenever you feel ready.