YOUR C LEARNING COMPANION

Kahan se padhein?

Learning path
Language ki detailsChapter 19 of 73

Keywords ko unke roles se samjhein

Types, declarations, control flow, type queries, generic selection aur function specifiers connect karein.

7 min readFoundationsC17 + C23 notes
Offline reading
Is chapter mein10 sections

Keyword ka job pata ho toh use yaad rakhna aasaan hota hai. Hum keywords ko unke work ke hisaab se group karenge aur pehle se jaane ideas se jodenge. Agle chapter ka index poori version-labelled list deta hai.

1. Type describe karein ya usko doosra naam dein

char, short, int, long, signed aur unsigned supported integer-type combinations banate hain. Yeh ek universal byte width choose nahi karte. float, double aur long double floating types hain; default se exact decimal arithmetic nahi. _Bool C17 Boolean type hai; void no value aur generic object-pointer form void * cover karta hai.

struct ordered members wale structure types, union shared-storage union types, aur enum enumerated types/constants introduce karte hain. ISO C arrays aur structures ko aggregates bolti hai; union separate type category hai. typedef type ka alias deta hai, distinct new type nahi.

C17 · illustrative fragment
typedef unsigned Count;
unsigned original = 2;
Count *same_type = &original;
*same_type = 3;

Count alias unsigned ke saath compatible hai kyunki same type name karta hai. Yeh special “sirf count” domain enforce nahi karta. Stronger interfaces ke liye deliberate representation aur validation policy chahiye; types aur data interfaces dekhein.

2. Declaration ke access aur lifetime rules refine karein

const, volatile, restrict aur _Atomic ka qualifier use alag access sawaalon ke answers hain. _Atomic(type-name) atomic type-specifier form bhi hai. Koi bhi universal “safer code” switch nahi. Contracts ke liye qualifiers chapter dekhein.

auto, register, static, extern, _Thread_local aur typedef C17 storage-class-specifier spellings hain. Grammatical category ka matlab nahi ki har ek storage allocate karta hai. Static ke block, file aur array-parameter roles alag hain; extern prior linkage inherit kar sakta hai. Storage classes context ke saath padhein.

3. Paths choose karein, work repeat aur control transfer karein

if/else scalar condition par branch karte hain. switch integer controlling expression use karta hai; case/default uske rules ke under labels hain. Matching case ke baad switch automatically stop nahi hota: koi transfer na roke toh control fall through kar sakta hai.

for, while aur do repetition organize karte hain. For preknown iteration count tak limited nahi; initialization, condition aur update ek construct mein rakhta hai. While body se pehle test karta hai; do body ke baad test karta hai agar control test tak pahunche.

C17 · illustrative fragment
int step = 0;
int total = 0;
for (; step < 5; ++step) {
    if (step == 2) continue;
    total += step;
}

Sum 8 hai: 0 + 1 + 3 + 4. Step 2 par continue ke baad bhi for update aata hai, isliye loop progress karta hai. break nearest enclosing loop/switch se exit karta hai. continue nearest enclosing loop ke continuation point ko target karta hai. return current function se exit karke return-type rules ke under optionally value deta hai.

goto same function ke label par jump karta hai, constraints ke saath, jaise variably modified scopes mein entry. Isse flow confusing ho sakta hai; bounded forward cleanup path ownership clear bhi kar sakta hai. Slogan ke bajay actual flow judge karein. Cleanup chapter woh use dikhata hai.

4. Type query ya translation-time contract check karein

sizeof C bytes mein size query karta hai; _Alignof type alignment query karta hai. _Alignas restrictions ke under declaration ki allowed alignment request karta hai; specific byte size nahi. _Static_assert required constant condition translation time par check karta hai.

Generic selection mein _Generic controlling expression ke type se ek association choose karta hai. Controlling expression evaluate nahi hota. C17 mein type specified as-if conversions ke saath determine hota hai; yeh har top-level qualifier preserve karne ka tool nahi.

C17 · illustrative fragment
int value = 3;
int result = _Generic(value++, int: 7, default: 9);

result 7 hai aur value 3 rehta hai. Selected result expression khud runtime work kar sakta hai. Unselected associations ko phir bhi syntax aur constraints satisfy karne hote hain, isliye doosre arm mein type-invalid expression hide nahi kar sakte. Translation-time categories ke liye constant expressions dekhein.

5. Optional: function specifiers rules wale promises hain

Function introduction ke baad inline aur _Noreturn

inline definition/linkage rules wala function specifier hai. Isse call ko body se replace karna guaranteed nahi; compiler inline ke bina bhi call expand kar sakta hai. Simple common header idiom static inline use karta hai: definition include karne wali har translation unit mein separate internal-linkage function.

Complete C17 program
#include <assert.h>

static inline int larger(int left, int right)
{
    return left > right ? left : right;
}

int main(void)
{
    assert(larger(3, 8) == 8);
    assert(larger(5, 5) == 5);
    return 0;
}

Yeh example ek translation unit hai. External-linkage inline definitions ke liye external definition provide karne ke additional C-specific rules hain; C++ inline assumptions C header mein copy mat karein. Expansion, function identity aur linking alag issues hain.

_Noreturn declare karta hai ki function caller ko return nahi karta. Yeh contract hai, returning ko safe banane wala optimization nahi. C23 [[noreturn]] attribute ke favor mein spelling deprecate karta hai; yahan noreturn attribute name hai, extra language keyword nahi.

6. Version changes spellings aur roles badalti hain

C23 bool, true, false, alignas, alignof, static_assert aur thread_local ko language spellings banata hai; purane header-macro routes par depend nahi karna padta. nullptr apne type wala predefined null-pointer constant hai; character '\0' ya NULL naam ka ordinary object nahi.

C23 constexpr, auto ke type-inference uses, typeof, typeof_unqual, _BitInt aur conditionally supported decimal floating types add karta hai. Typeof_unqual top-level aur atomic qualification remove karta hai, pointed-to const nahi: typeof_unqual(const int *const) ab bhi const int ka pointer denote karta hai.

_Complex/_Imaginary reserved type facilities hain jinke applicable support rules check karne chahiye; keyword reserved hone se har optional feature available prove nahi hota. Versions aur follow-up chapters ke liye complete keyword index dekhein.

7. Thought check: kya ek slogan keyword ka meaning fix karta hai?

Kya static ka har use “local calls ke beech survive karta hai” hai?

Nahi. Woh ek block-scope object case hai. File-scope static internal linkage establish karta hai; array-parameter static minimum access contract deta hai. Pehle declaration context identify karein, phir rule apply karein.

Sources aur aage ki reading

Primary references: WG14 N1570 6.2.5, 6.5.1.1, 6.5.3.4, 6.7.1–6.7.5, 6.7.8, and 6.8; WG14 N3096 (C23 notes). These are public committee drafts; the examples here use a C17 baseline. WG14 DR481 records the C17 generic-selection controlling-type correction; N1570 alone predates that correction. GCC inline documentation distinguishes its language modes.

Aage badhne se pehle

  • Keywords ko jobs se group karne par interpretation clear hota hai.
  • Spelling apne role ke according declarations, control flow ya special expression rules mein aa sakti hai.
  • Nayi spellings aur semantic changes ko selected C edition se jodein.
In ideas ko alag rakhein
Same spelling / Same rule
Familiar spelling ka meaning version-specific ho sakta hai; C aur C++ mein bhi rules alag ho sakte hain.
Apne words mein samjhaayein

Ek keyword choose karke memorised label ke bajaye rule aur small example se uska job explain karein.

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.

Function mein return ka main job kya hai?
Har choice ki explanation padhein
  1. Poore program ko hamesha turant terminate karna.

    Ordinary called function se return karne par normally caller resume hota hai.

  2. Function body repeat karna.

    return current invocation end karta hai, nayi iteration shuru nahi karta.

  3. Current function invocation finish karna aur required ho to value dena.

    ✓ Sahi reasoning. Function ka return type aur return statement value ke rules decide karte hain.

C17

Earlier edition ka quick reference

Existing section links aur saved passages ke liye retained. Exact corrections source review mein recorded hain.

C mein har keyword ka language ke andar ek specific role aur semantics hota hai. Neeche diye gaye paragraphs sabse important keywords aur unke usage ko explain karte hain, jahan zaroori ho wahan code examples ka reference bhi diya gaya hai.

Data Type Keywords

  • int, char, float, double, short, long, signed, unsigned: Yeh keywords arithmetic types ya type combinations specify karte hain. ISO C minimum requirements set karti hai; exact sizes aur ranges implementation par depend karte hain. Jaise int integer type hai aur unsigned long standard ki minimum requirements meet karne wali implementation-defined range ka unsigned integer type hai. Type ka choice memory usage, range, aur arithmetic behavior ko affect karta hai.

  • void: Value ki absence batata hai, jaise return value na dene wala function. void * generic object-pointer type hai; non-null void * phir bhi kisi real, typed object ko point kar sakta hai.

Control Flow Keywords

  • if, else, switch, case, default: Yeh keywords conditional branching implement karte hain. if aur else two-way branching allow karte hain, jabki switch, case, aur default ek expression ki value ke basis par multi-way branching enable karte hain.

  • for, while, do: Yeh keywords loops define karte hain. for counted loops ke liye use hota hai, while condition-controlled loops ke liye, aur do un loops ke liye jo kam se kam ek baar execute hote hain.

  • break, continue: break nearest enclosing loop ya switch se exit karta hai, jabki continue loop ke continuation point par control bhejta hai; for loop condition dobara test karne se pehle update expression evaluate karta hai.

  • goto: Kisi labeled statement par ek unconditional jump provide karta hai. Iska use generally discourage kiya jaata hai kyunki isse unstructured code ka risk rehta hai.

Storage Class Specifiers

  • auto: C17 mein automatic-storage specifier, jise ordinary local objects ke liye normally omit karte hain. C23 mein auto n = 10; jaise declarations se type inference bhi possible hai; yeh form C17 mein valid nahi hai.

  • register: Fast access suggest karta hai; CPU-register placement ya speed guaranteed nahi. Implementation suggestion ignore kar sakti hai, lekin C17 aur C23 register-declared object par direct unary & prohibit karte hain.

  • static: Thread-local storage ke bina ordinary object declarations mein static storage duration select karta hai; file scope par object/function identifiers ki internal linkage establish karta hai. Name visibility scope se decide hoti hai. Array parameters mein static ka distinct minimum-bound role hai.

  • extern: Commonly linkage wale object ya function ko declare karta hai, taaki different translation units same entity ko refer kar sakein. Iska matlab “hamesha kahin aur defined” nahi: file scope par extern int x = 1; definition hai. Header mein normally extern int x; aur ek source file mein single definition rakhein.

Type Qualifiers

  • const: Const-qualified lvalue ke through modification prevent karta hai. Originally const define kiye object ko const cast-away karke bhi modify karna undefined behavior hai. Mutable object ko pointer-to-const se dekhne par doosre valid non-const access path se change kiya ja sakta hai. Sirf const se ordinary C17 integer object integer constant expression nahi ban jaata.

  • volatile: Accesses ko special observable semantics deta hai; implementation-defined hardware access aur kuch signal-handler objects mein useful hai. Yeh atomic operations, threads ke beech memory ordering ya data races se protection nahi deta. Shared mutable thread data ke liye atomics ya appropriate synchronization use karein.

  • restrict: C99 ka pointer-access contract, jo optimization enable kar sakta hai. Associated execution mein relevant modified objects ke accesses par rules lagte hain; har doosre pointer ya saari read-only aliasing ko simply forbid nahi karta. Section 15 mein detail hai.

  • return: Function se exit karta hai aur optionally caller ko ek value return karta hai.

  • inline: C99 function specifier, jiske definition aur linkage rules hain. Call substitution implementation choice hai, guarantee nahi; compiler inline ke bina bhi calls expand kar sakta hai.

  • _Noreturn: Specify karta hai ki function caller ko return nahi karta (C11).

Other Keywords

  • struct, union, enum, typedef: struct, union aur enum respectively structure, union aur enumerated types introduce karte hain. ISO C ki aggregate category arrays aur structures ko include karti hai, unions ko nahi. typedef existing type ko doosra naam deta hai; distinct type create nahi karta.

  • sizeof: Type ya expression ka size C bytes mein deta hai; result type size_t hai. Operand usually evaluate nahi hota; variable-length-array types mein exceptions hain.

  • _Alignas, _Alignof: Memory alignment ko control aur query karte hain (C11).

  • _Atomic: Atomic types aur supported atomic operations specify karta hai (C11); overall thread safety ko phir bhi correct synchronization, lifetimes aur algorithm design chahiye.

  • _Thread_local: Thread-local storage declare karta hai (C11).

  • _Bool, _Complex, _Imaginary: Boolean, complex aur reserved imaginary-type support. Imaginary types optional hain; C11/C17 implementations complex types bhi omit kar sakti hain. C23 mein _Bool ki preferred spelling bool hai.

  • _Static_assert: Compile-time assertion (C11).

  • _Generic: Type ke basis par expressions select karke generic programming enable karta hai (C11).

Har keyword reserved hota hai aur user code mein isko identifier (variable ya function ka naam) ke roop mein use nahi kiya ja sakta.

Agla idea padhne ke liye tayyar?

Mark this chapter as read whenever you feel ready.

CHAPTER 19 / 73

Is chapter mein

Keywords ko unke roles se samjhein

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