Sunday, April 28, 2024
What is C Language?

Introduction of C Language

C language एक programming language है | जिसका use कर के applications बना सकते है | इसे unix operating system को दुबारा लिखने के लिए develop किया गया था | क्योकि unix operating system को B language में लिखा गया था। unix operating system मे जादातर programs भी B language मे लिखे गये थे |

B language को Ken Thompson के द्वारा 1970 में Bell laboratories में develop की गई थी। लेकिन B language ज्यादा popular नहीं हो पायी थी। फिर C language को Dennis Ritchie ने 1972 and 1973 में develop किया था। और C language को भी bell laboratories में ही develop किया गया था।

C language एक simple language है | C language के द्वारा जादा तर mathematical programs लिखे जाते है | और C language को popular होने मे जादा time नही लगा |

C language को Mother Language भी कहा जाता है क्यों C language के बाद जो भी language बनाई गयी for example ( Java , PHP , c# , या c++ ) इन सभी language मे C language का concept use किया गया है |

Versions of C Language

C Language को Brian Kernighan and Dennis Ritchie ने 1978 मे publish किया था | C language के अब तक कई version आ चुके है जिन्हें हम निचे blocks मे दे रहे है |

  1. K & R – यह C language का original language है | इस version को 1978 मे लाया गया था | और इस version मे Standard I/O library जैसी function available थी |
  2. ANSI C and ISO C – इस version को American National Standards Institute ( ANSI ) and
    International Organization for Standardization ( ISO ) के द्वारा 1989/1990 मे publish किया गया था |
  3. C99 – इस version को 1999 मे publish किया गया था | और इस version मे कुछ नये feature add किये गये थे जैसे – inline functions, several new data types, long int आदि |
  4. C11 – इस version को 2011 मे publish किया गया था | और इस version मे भी कुछ नये feature add किये गये थे जैसे – library, including type generic macros, anonymous structures आदि |
  5. C18 – इस version को June 2018 मे publish किया गया था |

Advantage of C language

  •  C language एक simple और easy language है | जिसका use आसानी से किया जा सकता है | और C language की सबसे बड़ी खासियत यह है | की C language मे लिखा गया code बहुत ही fast होता है | यानी C language की execution time fast होती है |
  • C एक structured programming language है। और C language मे हम functions बना सकते है | और अपने code को और भी अच्छे से manage कर सकते है |
  • C language मे C 32 reserved के द्वारा कुछ keyword provide की गयी है | जो ऐसे शब्द हैं, जिनका उपयोग किसी अन्य उद्देश्य के लिए नहीं किया जा सकता है | जिसके लिए वे पूर्वनिर्धारित हैं |
  • C एक middle level language है। जो high level और low level की application बनाने मे सक्षम है | यह feature उन programmers के लिए एक advantage है जो high level और low level की applications create करना चाहते है।
  • Assembly language के बाद सबसे fast language C language को ही माना जाता है | इसलिए ये दूसरी programming languages से fast होती है। C language में create की गयी applications की processing बहुत ही fast होती है।

Disadvantage of C language

C language एक powerful language है | लेकिन C language में कुछ कमियाँ भी है | जो C language को सीमित बनाती है। चलिए C language के कुछ Limitations के बारे मे जानते है |

  •  C language में run time checking नहीं होती है। C language में किसी भी variable के type को identify करने में सक्षम नही होती है।
  • C language मे re-usability ( inheritance ) support नहीं करती है। और C language में exceptions को run time में handle नहीं किया जा सकता है।
  • C language object oriented programming को support नहीं करता है | जैसे – classes, objects, interfaces आदि |

Usage of C Language

C language का use system application या network drivers बनाने के लिए किया जाता है | क्योंकि यह कोड का उत्पादन करता है | जो Assembly language में लिखे गए कोड के रूप में तेजी से चलता है। C language मे उपयोग के लिए कुछ उदाहरण निचे दे रहे है |

  • Operating Systems
  • Language Compilers
  • Assemblers
  • Text Editors
  • Print Spoilers
  • Network Drivers
  • Modern Programs
  • Data Bases
  • Language Interpreters
  • Utilities

C controll Statement

C Programming में Statement के सात प्रकार है-

  1. if Statement
  2. if_else Statement
  3. else_if Statement
  4. switch case Statement
  5. break Statement
  6. continue Statement
  7. goto Statement

1. if Statement

if Statement में अगर Condition true होती है तब Statement Execute होता है |

2. if_else Statement

if_else Statement में अगर Condition true हो तो वो if का statement Execute करता है | अगर Condition false होती है तो else का Condition करता है |

3. else_if Statement

else_if Statement में अगर if की Condition true होती है तो if का statement execute होता है | अगर if का condition false होता है तो वो अगले condition पर जाकर check करता है | अगर वो condition true होता है तो वो उसका statement execute करता है | अगर कोई भी condition true नहीं होती तो वो else का statement execute करता है |

4. switch case Statement

Switch case statement में expression होता है और उससे related कुछ cases होते है | जो case उस expression या declare किये हुए variable से match होती है तब वो output में print होता है | अगर कोई भी case expression से match नहीं होती तो वो default का statement output में print करेगा | आपको हर statement के बाद break लगाना पड़ता है, इसका मतलब वो उसके पहले का statement ही print करेगा | अगर आप break नहीं लगाते तो वो पहला और दूसरा ये दोनों statement को print करेगा | default case के बाद break नहीं लगाते |

5. break Statement

Break Statement Program के loops और switch case के execution का काम किसी condition पर बंद कर देता है |

6. continue Statement

Continue Statement Program के loops के condition के हिसाब से बीचवाले statements को skip कर देता है और बादवाले statement को execute करता है |

7. goto Statement

Go to ये C Programming का statement है | इसमें labels का use किया जाता है |
Goto Statement के दो प्रकार होते है |

  • Forward
  • Backward

जब goto statement कुछ statement को छोड़कर उसके अगले statement को execute करता है , उसे Forward goto statement कहते है और किसी पिछले या execute हुए statement को फिरसे execute करने के लिए अपने पिछले label पर जाता है , उसे Backward goto statement कहते है |

Introduction of Functions

C language मे function एक ऐसा method है | जिसे हम अपने according manage कर सकते है | और जरुरत पड़ने पर access भी कर सकते है | और जब भी function बनाते है | तो सबसे पहले data type declare करना पड़ता है | फिर function का एक unique name define करते है |
जब भी Function का name और parameters define करते है | तो उसे function declaration कहा जाता है। और जब हम function में execute होने वाले statements लिखते है | तो उसे function definition कहा जाता है। और जब program में कँही भी function को use करते है | तो उसे function call कहते है।

C language मे दो प्रकार के function provide किये गये है |

  • Predefined Functions
  • User defined Functions

Predefined Functions

C language मे Predefined functions वह functions होते है | जो library में पहले से ही provide किये गए है। यानी इन function को पहले से ही declare किया गया है। बस Predefined functions use करने के लिए हमे header files include करना होता है। उसके बाद Predefined functions use कर सकते है |

User Defined Function

  • C language मे User Defined Functions वो function होते है | जिसे programmer खुद create करता है | यानी इस type के functions को हम खुद create करते है | और अपने अनुसार use करते है |
  • C language मे User Defined Functions main() function के बाहर भी create कर सकते है | और main() function के अन्दर भी create कर सकते है |
  • जब भी हम User Defined Functions create करते है | तो उसका नाम अपने अनुसार रख सकते है | पर ध्यान रहे एक program मे 2
  • function एक नाम से नही होने चाहिए नही तो error आता है |
  • C language मे User Defined Functions का नाम main() function नही रख सकते है | क्योकि यह main() function है | जहा से हमारा program execute करना शुरू करता है |

Function Call

Program में जब भी function use करना चाहते है | तो हम उसे call करते है।जब भी हम function को call करते है | तो हमे arguments भी पास करने होते है | arguments हम तभी use करते है | जब हम function को declare करते समय parameter को पास किये रहते है | अगर आप function मे parameter पास नही किये है | तो आप function को directly call कर सकते है |

C language में functions को 2 प्रकार से call किया जा सकता है।

  • Call by Value
  • Call by Reference

Call by Value

जब हम function को call करते समय argument के रूप में कोई value पास करते है | तो वह parameter variables में copy हो जाता है | फिर function के अन्दर जो operation perform किया गया है | उसके अनुसार हमे result मिल जाता है |
इसी प्रकार जब हम function को call करते समय कोई variable पास करते है | तो उस variable की value parameter variable में copy किया जाता है | फिर function के अन्दर जो operation perform किया गया है | उसके अनुसार हमे result मिल जाता है |
अगर आप function को call करते समय variables पास करते है | तो ध्यान रहे जो variables function को call करने के लिए use कर रहे है | वह variables main() function मे declare होना चाहिए | नही तो program मे error आ जाता है |

Call by Reference

किसी function को call करने के लिए variables pass करने की बजाय उनका address भी पास किया जा सकता है। जो argument variables को ही point करेगा | इस तरह के function call में arguments को address of operator ( & ) के साथ pass किया जाता है। और parameters को value at ( * ) operator के साथ define किया जाता है।

Recursion

  • जिस function में वही function को call किया जाता है, उसे recursion कहते है |
  • Recursion एक ऐसा process है , जो loop के तरह काम करता है |
  • Recursion को एक satisfied condition लगती है, जिससे recursive function काम करना बंद कर दे |
  • Recursive Function तबतक call होता रहता है, जबतक उसका satisfaction नहीं होता |
  • अगर Recursive function का satisfaction नहीं हो तो ‘infinite looping’ की संभावना होती है |

Array

Array ये same data type के variables का collection होता है |
Array का data type कौनसा भी हो सकता है |
Array के variables अपने पासवाले Memory Location पर store होते है |
Array का initialization ‘0’ से शुरू होता

Array के दो प्रकार के है |

  1. Single/One Dimensional Array
  2. Multi Dimensional Array

Pointer

हर एक Variable का एक Memory Address होता है और Memory Address देखने के लिए Programmer को variable से पहले ‘&'(address operator) लगाना पड़ता है |
Pointer किसी दूसरे variable का address hold करके रखता है |
हर एक variable का एक address होता है | जब variable declare होता है तभी उसका एक memory location पर वो store होता है |
Pointers के दो Methods है |

  • Referencing Operator ( & )
  • Dereferencing Operator ( * )

Referencing Operator

Referencing मतलब किसी दूसरे variable का address hold करके रखना होता है |
हर variable का address hold करने के लिए जिसका address hold करना है और जिस Pointer variable में hold करना है, तो उन दोनों का data type same होना चाहिए |

Dereferencing Operator

Dereferencing में asterisk ( * ) का इस्तेमाल करते पर pointer में इसे Dereferencing Operator भी कहते है |Dereferencing में pointer में store किये हुए value को access किया जाता है |

dynamic memory allocation

C भाषा में dynamic memory allocation का concept सी प्रोग्रामर को runtime पर मेमोरी आवंटित करने में सक्षम बनाती है । Cdlib.h हेडर फाइल के 4 फंक्शन्स द्वारा c language में dynamic मेमोरी एलोकेशन संभव है।

  1. malloc()
  2. calloc()
  3. realloc()
  4. free()

Memory Allocation के लिए दो प्रकार है |

  •  Compile-time/Static Memory Allocation

जब variable को बनाया जाता है, तब Compiler के जरिये compile-time पर memory allocate की जाती है |
जब variable बनता है , तब वो किस data type से बनता है, तो compiler इसके हिसाब से खुद ही वो memory allocate करता है |
Variable का declaration Compile-time पर होता है |

  • Run-time/Dynamic Memory Allocation

Dynamic Memory Allocation में Run-time पर Memory allocate की जाती है |
Dynamic Memory Allocation में जब program run होता है तब Memory allocate की जाती है | यहाँ पर जरुरत के हिसाब से variables को बनाया जाता है | Dynamic Memory Allocation में variables का declaration नहीं किया जाता | सिर्फ compile-time पे variable को declaration किया जाता है | C Programming में जैसे Dynamic Allocation के लिए malloc, calloc, realloc और free का इस्तेमाल किया जाता है , वैसे ही C++ में दो ऐसे Operators है , जिनका इस्तेमाल Dynamic Memory Allocation के लिए किया जाता है |

String

हम char variable के बारे में जान चुके हैं कि यह variable किसी भी एक अक्षर(letter) को store करता है. अब अगर मान लीजिए कि हमें हमें एक word(जो एक से ज्यादा अक्षरों से मिलकर बना होगा) को store करना है तो उसे कैसे करेंगे? इसके लिए हम char की एक array बनायेंगे, चूंकि array एक ही तरह के एक से ज्यादा variable store कर सकता है अतः इसकी help से हम word या sentence store कर सकते हैं|

File Handlling

File Handling में data को secondary storage device(Hard disk) में permanently store किया जाता है |
File Handling को open, close, read, write के लिए इस्तेमाल किया जाता है |

Why use File handling

Program जब Programmer बंद करता है, तब program का सारा data destroy हो जाता है | Program में data store करने के Programmer कुछ variables, arrays, structures, unions का इस्तेमाल करता है, पर ये data permanently store नहीं होता | इसे permanently store करने के लिए ही File Handling का इस्तेमाल होता है | File Handling के दरम्यान create हुई files चाहे वो अलग-अलग types(.txt, .doc etc.) की हो वो portable होती है | दूसरे Computer में भी वो इस्तेमाल होती है |

File Handling के Operations

File Handling के Functions को इस्तेमाल करना हो तो stdio.h इस header file को include करना पड़ता है |

Operator Description
fopen() File को create और open किया जाता है |
fclose() Open किये हुई file को close किया जाता है |
fprintf() File में data को write किया जाता है |
fscanf() File में data को read किया जाता है |
fgetc() File से character को read किया जाता है |
fputc() File में character को write किया जाता है |
fseek() दिए हुई position पर file pointer को set किया जाता है |
getw() File से integer को read किया जाता है |
putw() File में integer को write किया जाता है |
ftell() File Pointer की current position return करता है |
rewind() File Pointer को file के शुरुआत में लाता है |
remove() File को remove कर देता है |

Introduction to C Console I/O

C language में input और output को 2 तरीके से process किया जा सकता है। एक तो आप console के माध्यम से input दे सकते है और output देख सकते है। C language में input और output के लिए ये standard और default तरीका होता है।
Console एक black window होती है जो input के समय compiler के द्वारा show की जाती है। Program के execution के बाद उसका result भी इसी window में दिखाया जाता है।
दूसरे तरीके में आप disk files को यूज़ करते हुए भी input दे सकते है और उनमें output भी store कर सकते है। ये totally application की need पर depend करता है की आप कौनसा तरीका यूज़ करते है।

Console I/O के लिए 2 standard device होते है।

  1. Keyboard : Keyboard एक standard input device है। By default एक C program keyboard के माध्यम से ही input लेता है।
  2. Monitor : Monitor (screen, LCD) एक standard output device होता है। यदि आप कोई दूसरा तरीका यूज़ नहीं करते है तो by default एक C program monitor पर ही output दिखाता है। लेकिन आप चाहे तो किसी external device पर भी output show कर सकते है।
Tags: , , , , , , , ,
Avatar
My name is Yash Pogra and I am the chief blogger at Codeash and where I like to share my internet/tech experience with my online readers on this website. I have been a webmaster from 2015 which is when I had registered my first company by the name Codeash. I have ventured into different online businesses like offering SEO Services, website development services.

Related Article

No Related Article

2 Comments

Avatar
manish kumar 04/08/2022 at 9:02 pm

i want talk to u
related to the job

Avatar
manish kumar 04/08/2022 at 9:02 pm

i want talk to u
related to the job..

Leave a Comment