SlideShare uma empresa Scribd logo
1 de 109
[i]
Copyright & Disclaimer
 Copyright 2017 by www.besthinditutorials.com. All the content and graphics
published in this e-book are the property of www.besthinditutorials.com. The user of
this e-book is prohibited to reuse, retain, copy, distribute or republish any contents
or a part of contents of this e-book in any manner without written consent of the
publisher. We strive to update the contents of our website and tutorials as timely
and as precisely as possible, however, the contents may contain inaccuracies or
errors. www.besthinditutorials.com provides no guarantee regarding the accuracy,
timeliness or completeness of our website or its contents including this tutorial. If
you discover any errors on our website or in this tutorial, please notify us at
contact@besthinditutorials.com
https://www.facebook.com/besthinditutorials
https://twitter.com/BH_Tutorials
https://plus.google.com/+Besthinditutorialscom
[ii]
Table of Contents
.................................................................................................................................1What is Programming?
Introduction to Programming..............................................................................................................1
Programming Language............................................................................................................................1
Compiler / Interpreter.............................................................................................................................3
Programmer ......................................................................................................................................................3
...................................................................................................................................4Basics of C Language
Introduction to C language..................................................................................................................4
A simple program in C language.................................................................................................6
................................................................................................................................7C Compiler Installation
Introduction to Dev C++ Compiler ................................................................................................7
Installing Dev C++ compiler...............................................................................................................7
Working with Dev C++ compiler...................................................................................................12
....................................................................................................16C Tokens, Identifiers & Keywords
Introduction to C Tokens.....................................................................................................................16
C Character Set...........................................................................................................................................17
Identifiers.........................................................................................................................................................17
Keywords ..........................................................................................................................................................18
.....................................................................................................................................................19C Data Types
Introduction to C Data Types ..........................................................................................................19
Different C data types ...........................................................................................................................19
Void type..........................................................................................................................................................21
...........................................................................................................................22C Variables & Constants
Introduction to C variables ................................................................................................................22
Scope of variables.....................................................................................................................................24
Constants in C..............................................................................................................................................25
...................................................................................................................................................28C Flow Charts
Introduction to Flow Chart.................................................................................................................28
[iii]
Symbols of Flow Chart ..........................................................................................................................29
Example of Flow Chart..........................................................................................................................30
...............................................................................................................................................32First C program
C program development life cycle ................................................................................................32
Structure of A C program...................................................................................................................33
Your first C program...............................................................................................................................33
Commenting ....................................................................................................................................................34
.........................................................................................................................................................35C Operators
Introduction to C operators...............................................................................................................35
.........................................................................................................................................46C Decision Making
Introduction to C decision making...............................................................................................46
If statement...................................................................................................................................................47
If-Else statement........................................................................................................................................48
Switch statement........................................................................................................................................49
.............................................................................................................................................................52C Looping
Introduction to C language looping.............................................................................................52
C while loop ..................................................................................................................................................53
C Do-while loop ..........................................................................................................................................54
C For loop .......................................................................................................................................................55
................................................................................................................................................................56C Arrays
Introduction to C arrays ......................................................................................................................56
Creating c arrays........................................................................................................................................56
Initializing C arrays..................................................................................................................................57
Accessing array elements.....................................................................................................................58
Two Dimensional Arrays .......................................................................................................................59
...............................................................................................................................................................63C Strings
Introduction to C strings .....................................................................................................................63
gets() and puts() functions ...............................................................................................................64
[iv]
Other string functions ............................................................................................................................65
.........................................................................................................................................................66C Functions
Introduction to C functions................................................................................................................66
Predefined & user defined functions ..........................................................................................66
Advantages of functions........................................................................................................................67
Creating & using functions in C ....................................................................................................67
Example .............................................................................................................................................................70
.......................................................................................................................................................71C Structures
Introduction to C structures..............................................................................................................71
Defining a structure.................................................................................................................................71
Creating structure variables...............................................................................................................72
Accessing structure members ...........................................................................................................73
Example .............................................................................................................................................................73
...............................................................................................................................................................75C Unions
Introduction to C unions.................................................................................................................75
.........................................................................................................................................................78C Recursion
Introduction to C Recursion ..............................................................................................................78
Types of Recursion ...................................................................................................................................79
Example of Recursion (Factorial).......................................................................................................80
............................................................................................................................................................83C Pointers
Introduction to C pointers..................................................................................................................83
Working with pointers............................................................................................................................84
Example .............................................................................................................................................................85
..........................................................................................................................................87C Storage Classes
Introduction to C storage classes.................................................................................................87
................................................................................................................................................91C File Handling
Introduction to C file handling .......................................................................................................91
Opening a file...............................................................................................................................................91
[v]
Reading from a file..................................................................................................................................93
Writing to a file .........................................................................................................................................94
Closing a file.................................................................................................................................................94
.............................................................................................................................................95C Error Handling
Introduction to C error handling...................................................................................................95
exit() function...............................................................................................................................................97
..................................................................................................................................................98C Header Files
Introduction to C header files.........................................................................................................98
Types of header files..............................................................................................................................98
Working with header files...................................................................................................................99
....................................................................................................................101C Preprocessors Directives
Introduction to C preprocessor directives.............................................................................101
1 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
What is Programming?
 Introduction to programming in Hindi
 Programming language in Hindi
 What is Compiler in Hindi
 Who is Programmer in Hindi
Introduction to Programming
India में हर साल लाखों students computer scientists बनते है। हालााँकि एि
computer scientist ससर्फ programming ही नहीीं िरता है, लेकिन programming
computer science िा बहुत ही महत्वपूर्फ part है। इससलए एि शुरआती programmer
होने िे नाते आपिे सलए programming और उससे related components िा concept
ठीि से समझना बहुत जरुरी है। कितने ही ऐसे programmers होते है जो programming
तो िर रहे होते है लेकिन उनिो programming िे पीछे िा concept नहीीं पता होता है।
आइये इसिे बारे में जानने िा प्रयास िरते है।
आसान शब्दों में िहा जाये तो programming एि ऐसी process होती है जजसमें एि
programmer CPU (Central Processing Unit) िो िोई task perform िरने िे
instructions देता है। ये task िु छ भी हो सिता है जैसे िी दो numbers िो add
िरना आदद।
Programming िु छ components से समलिर एि समग्र रूप धारर् िरती है।
1. Programming Language
2. Compiler / Interpreter
3. Programmer
इन components िे बारे में ननचे detail से बताया जा रहा है।
Programming Language
Humans जब भी interact िरते है तो किसी language िे माध्यम से िरते है। एि
CPU िो भी आप language िे माध्यम से ही instructions देते है। ऐसी language जो
CPU िो instructions देने िे सलए programmers यूज़ िरते है programming
language िहलाती है।
CPU ससर्फ binary language (0 & 1) िो ही समझता है। लेकिन किसी भी human िे
सलए binary language में programming िरना असींभव है। इससलए simple English
sentences िो यूज़ िरते हुए programming languages develop िी गयी।
2 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
ऐसा िरने से programming िरना बहुत अधधि आसान हो गया। अब जैसा िी आप देख
सिते है हर िोई basic information प्राप्त िरिे programming िरना ससख सिता है।
लेकिन पहले ऐसा सींभव नहीीं था।
Types of Programming Languages
अब ति 256 से अधधि programming languages develop िी जा चुिी है। हर
language िो एि different purpose िे सलए develop किया गया है। Purpose िे
according programming languages िो mainly 5 categories में divide किया
गया है।
1. Machine Language / Machine Code - ये वो code होता है जजसे CPU
directly execute िरता है। Machine code hexadecimal में होता है। ये
hardware िे बहुत ही िरीब होता है। इसे low level language भी िहा जाता
है।
2. Assembly Language - Machine code िो और भी अधधि readable बनाने िे
सलए assembly language create िी गयी। इसमें labels िो add किया गया है
जजससे tasks perform िरना और भी आसान हो जाता है। ये भी एि low level
language होती है।
3. High-Level Language - High level languages hardware से independent
होती है जैसे िी c, c++, java आदद। इन languages िा code directly
machine code में convert नहीीं होता है।
4. System Language - इस प्रिार िी languages computer िो manage िरने
िे सलए यूज़ िी जाती है। इन्हें low level tasks perform िरने िे सलए यूज़
किया जाता है। जैसे िी memory management, procsess management
आदद।
5. Scripting Languages - इस प्रिार िी languages system और दूसरी
applications िे बीच में bridge िी तरह िाम िरती है। जैसे िी PHP आदद।
Some Common Programming Languages
याँहा पर िु छ programming languages िी list दी जा रही है। इनमें से िु छ िे बारे में
आप सुन चुिे होंगे।
 C Language
 C++
 Java
 C#
 PHP
 HTML
 JavaScript
3 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
 Pascal
 Visual Basic
 FORTRAN
Compiler / Interpreter
जैसा िी मैने आपिो बताया computer ससर्फ binary language समझता है और
humans िा binary में programming िरना बहुत मुजकिल है। इससलए एि ऐसा
program develop किया गया जो programmers से simple English statements िे
रूप में instructions ले सिे और उसे binary में convert िरिे CPU िो pass िर दे।
इस program िो compiler िहते है।
Compiler एि programmer और CPU िे बीच bridge िी तरह िाम िरता है। इसे
आप translator भी िह सिते है। एि compiler बहुत से tasks perform िरता है
इनिे बारे में ननचे ददया जा रहा है।
 Compiler syntax error check िरता है। यदद िोई syntax error होती है तो
इसिे बारे में programmer िो notify किया जाता है।
 Compiler source code िो machine language में convert िरता है।
 Compiler एि machine executable file generate िरता है।
आइये अब interpreter िे बारे में जानने िा प्रयास िरते है।
िु छ languages compiler िी जगह interpreter भी use िरती है। Compiler और
interpreter दोनों एि ही िाम िरते है। र्िफ ससर्फ इतना होता है िी compiler पुरे
source code िो एि साथ compile िरिे machine code generate िरता है जजसे
एि बारे में completely execute किया जा सिता है। जबकि एि interpreter एि एि
instructions िो machine code में convert िरता है और साथ िी साथ execute
िरता जाता है। अपनी need िे according languages compiler और interpreter िो
यूज़ िरती है।
Programmer
शुरूआती ददनों में लोग interest िी वजह से programming िरते थे लेकिन अब इसने
एि job िा रूप धारर् िर सलया है। Programmer वह person होता है जजसे िी किसी
programming language िा ज्ञान होता है। एि programmer अपने ज्ञान िो यूज़
िरते हुए programming language िी मदद से real world problems िो solve
िरता है।
4 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
Basics of C Language
 Introduction to C in Hindi
 Characteristics & Features of C in Hindi
 Limitations of C in Hindi
 Applications of C in Hindi
 A simple C program
Introduction to C language
C एि बहुत ही popular programming language है। इसे Middle level language
माना जाता है। आज भी C िी popularity में िोई िमी नहीीं आई है। किसी भी दूसरी
language िो ससखने से पहले C िो सीखना बहुत जरुरी है। क्योंकि C िे बाद जजतनी भी
programming languages आई उन्होंने किसी न किसी तरह C िे features िो
adopt किया है। आइये C िे बारे में detail से जानने िा प्रयास िरते है।
History
C एि structured general purpose programming language है। इसे UNIX
operating system िो दुबारा सलखने िे सलए develop किया गया था। इससे पहले
UNIX operating system िो B language में सलखा गया था। पूरा UNIX operating
system और उस पर run होने वाले ज्यादातर programs C language में ही सलखे गए
है।
B language Ken Thompson िे द्वारा 1970 में Bell laboratories में सलखी गई
थी। B एि type less language थी। C language िो Dennis Ritchie ने 1972
में Bell laboratories में ही develop किया था। C language बहुत से data types
provide िरती है।
C language िे syntax िो बहुत सी popular languages ने follow किया है। C िा
improved version C# है। C िे features िो Java और C++ जैसी languages ने
follow किया है।
5 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
Characteristics & Features
 C एि modular language है। C में एि बडे program िो छोटे छोटे
modules (functions) िे रूप में divide किया जाता है। ऐसा िरने से
programs िो manage और debug िरने में आसानी रहती है।
 C एि flexible language है। C 32 reserved keywords provide िरती है।
ये keywords programmer िो language पर control provide िरते है। इन
keywords िी मदद से program िे structure िो भी modify किया जा सिता
है।
 C language Assembly language िे बाद सबसे fast language मानी जाती
है। इसे िई बार low level language भी िहा जाता है। C language
hardware िे बहुत िरीब होती हैं। इससलए ये दूसरी programming languages
से fast होती है।
 C एि case sensitive language है।
 C High level और low level दोनों तरह िे programs create िरने में सक्षम
है।
 C एि extendable language है। C programs में libraries िे द्वारा आप
िभी भी नए features add िर सिते है।
Limitations
 C language में run time type checking नहीीं होती है। C language run
time में किसी भी variable िे data type िो identify िरने में असमथफ होती
है। उदाहरर् िे सलए float data type में integer value डाली जा सिती है।
 C language में object oriented concepts नहीीं होते है।
 C language में constructors और destructors िा concept भी नहीीं होता है।
 C language में namespaces िा concept नहीीं होता है। इससलए different
programmers िे code िो एि ही project में यूज़ िरना बहुत मुजकिल होता है।
 C language code िी re-usability िो support नहीीं िरती है।
 C language में exceptions िो run time में handle नहीीं किया जा सिता है।
Applications
 ज्यादतर operating systems C language में ही बनाए जाते है। जैसे िी UNIX,
Windows आदद।
 किसी भी नयी programming language िो compile िरने िे सलए compilers
िी आवकयिता होती है। C language में compilers भी create किये जाते है।
6 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
उदाहरर् िे सलए java िा compiler javac भी C language में ही बनाया गया
है।
 C language में िई प्रिार िे assemblers भी create किये जाते है।
Assembler basic instructions िो bits में convert िरते है।
 C language में text editors भी create किये जा सिते है। जैसे िी gedit,
आदद।
 C language में network drivers भी create किये जाते है।
 C language में database systems भी सलखे जाते है। जैसे िी oracle
database C में ही सलखा गया है।
A simple program in C language
#include <stdio.h>
int main()
{
printf("Hello Readern");
return 0;
}
ऊपर ददया गया program ननचे ददया गया output generate िरता है।
Hello Reader
7 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
C Compiler Installation
 Introduction to Dev C++ compiler in Hindi
 Installing Dev C++ compiler in Hindi
 Working with Dev C++ compiler in Hindi
Introduction to Dev C++ Compiler
जैसा िी आपिो पता है एि compiler programmer द्वारा किसी programming
language में सलखे गए code िो machine executable form में convert िरता है।
C language िे सलए अलग अलग platforms िे अनुसार बहुत से compilers available
है।
Dev C++ एि (Integrated Development Environment) है। इसिे माध्यम से c या
c++ में programming िरना बहुत ही आसान हो जाता है। ये IDE आपिो graphical
user interface provide िरती है और साथ ही आपिो automatic code completion,
syntax highlighting और एि साथ िई files िे साथ work िरने िी ability provide
िरती है।
Best Hindi Tutorials िे readers िे सलए इस ही IDE िो recommend किया जाता
है। हालााँकि अभी भी िई university और colleges में Turbo C compiler िो use
किया जा रहा है लेकिन ये IDE आपिो better development environment provide
िरता है इससलए आपिो इसे ही use िरना चादहए।
Installing Dev C++ compiler
इस IDE िो आप Dev-C++ Download Page से download िर सिते है। इसे
install िरना ननचे steps िे द्वारा समझाया जा रहा है।
1. जैसे ही आप setup.exe file िो download िरिे उस पर click िरेंगे तो आपिो
ननचे दी गयी window show होगी।
8 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
ऊपर दी गयी window में आपिो अपनी preferred language select िरनी है।
Default language English है। याँहा पर आप OK click िरेंगे।
2. इसिे बाद आपिो ननचे दी गयी screen show होगी।
ये licence agreement िी window है। याँहा पर आप I Agree button पर click
िरेंगे।
3. इसिे बाद आपिो ननचे दी गयी window show होगी।
इस window में आपिो type of installation select िरना होता है। ये window
आपिो 3 (Full, Typical और Custom) options provide िरती है। आप अपनी need
िे according िोई भी installation type select िर सिते है। Installation type
select िरने िे बाद आप next पर click िरेंगे।
4. इसिे बाद आपिो ननचे दी गयी window show होगी।
9 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
इस window में आप वह location बताते है जाँहा पर आप Dev C++ िो install िरना
चाहते है। By default ये c drive में install होगा। Location set िरने िे बाद आप
Install button पर click िरेंगे।
5. इसिे बाद आपिो ननचे दी गयी window show होगी।
ये installation progress window है। इस window में आपिो िोई action नहीीं लेना
है।
6. ऊपर दी गयी progress window िे complete होते ही आपिो ननचे दी गयी
window show होगी।
10 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
ये completion window है याँहा पर आपिो Finish button पर click िरना होगा।
7. इसिे बाद आपिो ननचे दी गयी window show होगी।
ये first time configuration window होती है। इस window में आप language और
Dev c++ िी theme select िरते है। इसिे बाद आप next button पर click िरेंगे।
8. इसिे बाद आपिो ननचे दी गयी window show होगी।
11 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
इस window में आपसे पूछा जा जायेगा िी क्या आप Dev C++ िो Header files िे
साथ use िरना चाहते है। याँहा पर आप Yes, I want to use this feature option
िो select िरेंगे।
9. इसिे बाद आपिो ननचे दी गयी window show होगी।
इस window में आपसे cache create िरने िे सलए पूछा जाएगा। इस window में आप
Yes, create the cache option select िरेंगे।
10. इसिे बाद आपिो ननचे गयी window show होगी।
12 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
ये window आपिो बताती है िी Dev C++ िो successfully configure िर सलया
गया है। इस window में आप OK button पर click िरेंगे।
11. इसिे बाद आपिो ननचे दी गयी window show होगी।
ये Dev C++ िी window है। अब आपिे PC में Dev C++ successfully install हो
चूिा है।
Working with Dev C++ compiler
याँहा पर मैं आपिो Dev C++ compiler में एि simple program बनािर उसे
execute िरिे बता रहा हूाँ जजससे आप इसिे basic uses िो समझ पाएींगे।
सबसे पहले आप Dev C++ compiler िो open िरेंगे। इसिे बाद आप एि नयी file
create िरेंगे। नयी file create िरने िे सलए आप Menu bar में File option पर
click िरेंगे और इसिे बाद new menu में जािर source file पर click िरेंगे। जैसा िी
ननचे दी गयी window में show किया गया है।
13 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
जैसे ही आप Source File option पर click िरेंगे right side में editor open हो
जायेगा। जैसा िी ननचे दी गयी image में show हो रहा है।
याँहा पर आप अपना code सलखते है। जैसे िी ननचे गयी image में show हो रहा है।
14 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
Code सलखने िे बाद आप अपने program िो compile िरते है। इसिे सलए आप
Execute menu में जािर compile option पर click िरते है। जैसा िी ननचे दी गयी
image में ददखाया गया है।
Compile option पर click िरते ही आपिो एि window show होगी जजसमे आपिो इस
program िो save िरने िे सलए िहा जाएगा। जैसे िी ननचे दी गयी image में show
हो रहा है।
जैसे ही आप इस program िो किसी name िे साथ save िरते है program compile
होना शुरू हो जाएगा। यदद program में िोई error है तो वह editor िे ननचे show
होगी नहीीं तो program successfully compile हो जाएगा और done िा message
show िरेगा।
15 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
Program िे compile होने िे बाद आप इसे run िरेंगे। Program िो run िरने िे
सलए आप Execute menu में जािर run option पर click िरेंगे। इसिे बाद आपिा
program run हो जाएगा और आपिो console window में output show होगा। जैसा
िी ननचे दी गयी image में show हो रहा है।
16 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
C Tokens, Identifiers & Keywords
 Introduction to C tokens in Hindi
 C character set in Hindi
 C Identifiers in Hindi
 C keywords in Hindi
Introduction to C Tokens
C language िा syntax िई दूसरी popular languages िे द्वारा follow किया गया
है, इससलए C िा syntax समझना आपिे सलए बहुत आवकयि है। C program tokens
से समलिर बना होता है। जैसे िी ननचे ददए गए program िो देखखये। ये program
tokens िा सही क्रम में यूज़ है और इसिे ससवा िु छ भी नहीीं है। यदद आप C िे सभी
tokens िो यूज़ िरना ससख ले तो आप C िे expert बन जायेंगे।
#include <stdio.h>
int main()
{
printf("Software programming is cool");
print("%d",5);
}
Tokens 6 types िे होते है। इनिी list ननचे दी जा रही है।
 Identifier
 Keyword
 Constant
 Variable
 String
 Operator
यदद इस list िे according आप देखें तो ऊपर ददए गए program में int, main,
printf ,+ और Software programming is cool आदद सब िु छ tokens ही है। इनमें
से सभी tokens िे बारे में अभी ना बतािर में याँहा पर आपिो ससर्फ Identifiers और
keywords िे बारे में बताने जा रहा हूाँ। बाकि tokens िे बारे में आपिो आगे िी
tutorials में बताया जायेगा।
मै समझता हूाँ िी आपिो tokens क्या है ये concept clear हो गया होगा। अगर ऐसा
है तो आइये िु छ tokens िे बारे में detail से जानने िा प्रयास िरते है। लेकिन इससे से
पहले में आपिो C language िे character set िे बारे में बताने जा रहा हूाँ।
17 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
C Character Set
C language में आप program characters िी sequence में सलखते है। जैसे िी
#include <stdio.h> ये statement characters से ही बना है। याँहा पर i,n,c,l और
h आदद characters है। लेकिन ऐसा नहीीं है िी आप C program में िोई भी
character यूज़ िर सिते है। इसिे सलए C िे द्वारा character set define किया गया
है। जो characters इस set में है िे वल वे ही एि C program में यूज़ किये जा सिते
है।
Alphabet
Alphabet characters में आप A से Z upper case और a से z lower case
characters िो यूज़ िर सिते है।
Digits
Digits में आप 0 से लेिर 9 ति िी िोई भी digits यूज़ िर सिते है।
Special characters
Special characters में आप ननचे ददए गए characters िो यूज़ िर सिते है।
! @ # $ % ^ & * ( ) _ - + = |  { } [ ] < > ", ? /
इन alphabet digits और special characters िे अलावा आप िोई और character C
language में यूज़ नहीीं िर सिते है। इसे ही C िा character set िहते है।
Identifiers
Identifiers वो नाम होते है जो आप variables, constants और functions आदद िो
देते है। इन नामों िो देने िे सलए भी िु छ ननयम है जो आप follow िरते है। यदद आप
इन ननयमों िो follow नहीीं िरते है तो program में error आ जाती है। ये ननयम आगे
बताये जा रहे है।
1. Identifiers में @, %, - characters allowed नहीीं है।
2. C case sensitive language है। इससलए age और Age 2 different
identifiers है।
3. Identifiers में आप operators नहीीं यूज़ िर सिते है।
18 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
4. Identifier िी शुरआत आप या तो character या underscore से िर सिते है।
Digits से identifier िो start नहीीं किया जा सिता है।
5. आप A से लेिर Z ति िे small और capital दोनों तरह िे letters या कर्र
underscore में से किसी िे साथ भी identifiers िो start िर सिते है। इसिे
बाद आप digits और दूसरे characters या underscore यूज़ िर सिते है।
Example
_age // Valid
2name // Invalid
Emp-name // Invalid
Emp_2_age // Valid
Keywords
Keywords िो predefined tokens या reserved words भी िहते है। C language
32 keywords provide िरती है। हर keyword िा एि खास मतलब होता है। हर
keyword िो एि particular task perform िरने िे सलए define किये गया है। इन
keywords िी list ननचे दी जा रही है। इन keywords िो याँहा पर explain नहीीं किया
जा रहा है। इनिे बारे में आप धीरे धीरे आगे आने वाली tutorials में जानेंगे।
auto break case char const continue
default do double else enum extern
float for goto if int long
register return short signed sizeof static
struct switch typedef union unsigned void
volatile while
19 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
C Data Types
 Introduction to C data types in Hindi
 Different C data types in Hindi
 Integer type in Hindi
 Floating point type in Hindi
 Char type in Hindi
Introduction to C Data Types
जब भी आप िोई variable create िरते है तो उससे पहले compiler िो बताते है िी
आप किस तरह िा data उस variable में store िरेंगे। इससे compiler उतनी ही
memory उस variable िो computer िी memory में से allot िर देता है। जैसे िी
ननचे ददए गए statement िो देखखये।
int age;
ऊपर ददया गया statement compiler िो बताता है िी आप age variable में एि
whole number store िरने वाले है। किसी भी whole number िो store िरने िे
सलए जजतनी memory िी आवकयिता होती है compiler उतनी इस variable िो allot
िर देता है। जो िी 2 bytes है।
अब आप सोच सिते है िी यदद किसी programming language में data types ना हो
तो कितनी memory waste हो सिती है। जाँहा पर 2 bytes िी requirement हो वाँहा
20 bytes आप waste िर सिते है।
इस प्रिार जजतनी भी तरह िा data आप store िर सिते है उसिे सलए पहले से ही
maximum memory limit define िी गई है। आइये अब C िे अलग अलग तरह िे
data types िे बारे में जानने िा प्रयास िरते है।
Different C data types
C language 3 तरह िे data types िो support िरती है। इन्हें primitive types भी
िहते है।
 Integer
o int
o short int
o long int
o singed int
o unsigned int
 Floating point
o float
o double
20 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
 Character
o char
Integer
Integer types किसी भी whole number (बबना दशमलव िे ) िो store िरने िे सलए
यूज़ किये जाते है। Integer types 5 प्रिार िे होते है। हालाींकि ये सभी whole number
िो store िरते है। लेकिन memory size और range िे base पर इन्हें categories
किया गया है।
Data type Size (Bytes) Range
int 2 -32768 से 32767
short int 1 -128 से 127
long int 4 -2,147,483,648 से
2,147,483,647
signed int 2 -32768 - 32767
unsigned int 2 0 - 65535
Example
long int population = 200000000;
Floating point
Floating point data types िो दशमलव सींख्याओीं िो store िरने िे सलए define
किया गया है। Floating point data types 2 तरह िे होते है। इनिो size और range
िे base पर categories किया गया है। Float type में आप दशमलव िे बाद 7
digits ति store िर सिते है। Double type में दशमलव िे बाद 17 digits ति
store िी जा सिती है।
Data types Size (Bytes) Range
Float 4 3.4E-38 से 3.4E+38
Double 8 1.7E-308 से 1.7E+308
Example
double balance=810.12354984;
21 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
Character
Character type िो एि character store िरने िे सलए यूज़ किया जाता है। इनिो 2
categories में divide किया गया है।
Data type Size (Bytes) Range
char 1 -128 से 127
unsigned char 1 0 से 255
Example
char bestlanguage = "C";
Void type
Void type िो उन situations में यूज़ किया जाता है जब आपिो value िे बारे में िोई
जानिारी ना हो। इसे functions िे साथ ज्यादातर यूज़ किया जाता है। C में void type
िो आप इन situations में यूज़ िर सिते है।
1. यदद आपिा function िोई value return नहीीं िरता है तो आप उसिा return
type void define िरते है। उदाहरर् िे सलए आप इस प्रिार function define
िर सिते है। void myFunction();।
2. यदद आप function में िोई parameters नहीीं ले रहे है तो आप वाँहा पर void
define िर सिते है। Void type से पता चलता है िी इस function में िोई
argument नहीीं सलया जाता है। उदाहरर् िे सलए आप इस प्रिार void िो
parameter िे रूप में pass िर सिते है। int myFunction(void);।
3. यदद आप sure नहीीं है िी pointer variable किस type िे variable िो point
िरेगा तो आप उसिा type void declare िर सिते है। इसिे बाद आप void
pointer से किसी भी variable िो point िर सिते है।
22 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
C Variables & Constants
 Introduction to C variables in Hindi
 Creating C variables in Hindi
 Scope of C variables in Hindi
 Introduction to C constants in Hindi
Introduction to C variables
यदद आप computer िी memory में data िो store िरना चाहते है तो इसिे सलए
पहले आपिो उस memory location िे सलए नाम देना होता है। Variable memory में
किसी location िा नाम होता है।
मान लीजजए ये आपिा computer memory space है। आप इसमें िु छ data store
िरवाना चाहते है। जैसे िी किसी व्यजक्त िी उम्र आदद। Computer िी memory में
data store िरवाने से पहले आप बताते ही िी आप किस तरह िा data store िरेंगे।
ये आप data types िे द्वारा define िरते है। उसी िे according आपिो memory में
space समलता है। यानन िी यदद आपने int define किया है तो 2 bytes आपिो
memory में compiler allot िरेगा।
इसिे साथ ही आपिो उस memory location िा नाम भी define िरना होता है। ताकि
आप जब भी चाहे उस memory location में store िी गई value िो इस नाम िे
द्वारा access िर सिे । इस नाम िो ही variable िहते है। Variables िी values
changeable होती है। आप एि value िो हटािर दूसरी value डाल सिते है। ऐसा आप
manually खुद भी िर सिते है या कर्र dynamically (program execution िे दौरान)
भी िर सिते है।
23 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
Creating variables in C
Variables create िरने िे सलए सबसे पहले आप data type define िरते है। इसिे
बाद आप एि unique name define िरते है। इसिा structure इस प्रिार होता है।
dataType variableName; // without assigning value
dataType variableName = value; // with value assignment
उदाहरर् िे सलए ननचे ददए गए statement िो देखखये।
int Age = 25;
इस statement िे द्वारा एि integer variable create किया गया है, जजसिा नाम
Age है और इस variable िो 25 value assign िी गई है। आइये अब समझते है िी
compiler इस statement िो किस प्रिार interpret िरता है।
जब compiler सबसे पहले int िो interpret िरता है तो वह computer िी memory
में से 2 bytes िी memory allot िरता है। इसिे बाद जब compiler Age िो
interpret िरता है तो वह उस 2 bytes िी memory िो age नाम दे देता है। इसिे
बाद जब compiler = 25 िो interpret िरता है तो 25 िो इस memory location
store िर देता है।
अब जब भी आप इस value िो access िरना चाहते है Age िे द्वारा इसे access िर
सिते है।
24 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
Scope of variables
िोई variable program में िाँ हा ति िाम िर सिता है। ये उसिा scope होता है।
Scope िे according variables िो 2 categories में divide किया गया है।
Local variables
Local variables वो variables होते है जो program िे किसी छोटे block में define
किये जाते है जैसे िी function या control statement blocks या िोई और block ({
}) भी हो सिता है। इस तरह िे variables िा यूज़ ससर्फ इस block ति ही limited
रहता है। जैसे िी यदद आपने किसी function में िोई variable create किया है तो आप
उस variable िो उस function िे बाहर access नहीीं िर सिते है। उदाहरर् िे सलए
ननचे ददए गए program िो देखखये।
#include <stdio.h>
void myFunction();
int main()
{
int num=6;
myFunction();
printf("Num in main() : %d", num);
return 0;
}
void myFunction()
{
int num= 5;
printf("Num in myFunction : %dn",num);
}
ऊपर ददया गया program ननचे ददया गया output generate िरता है।
Num in myFuntion() : 5
Num in main() : 6
25 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
Global variables
Global variables वो variables होते है जजनिा scope पुरे program में होता है। इन
variables िो आप पुरे program में िीं ही भी access िर सिते है। इसिा उदाहरर् ननचे
ददया जा रहा है।
#include <stdio.h>
int num=5;
void myFunction();
int main()
{
myFunction();
printf("Num in main() : %d",num);
return 0;
}
void myFunction()
{
printf("Num in myFunction : %dn",num);
}
ऊपर ददया गया program ननचे ददया गया output generate िरता है।
Num in myFunction() : 5
Num in main() : 5
Constants in C
Constants वो variables होते है जजनिी value change नहीीं होती है। जब भी आप
िोई constant declare िरते है तो program िे execution िे दौरान उसिी value
fixed रहती है। यदद इसिी value change िरने िी िोसशश िी जाती है तो program
में error आ जाती है। इन्हें literals भी िहा जाता है।
Constants िो आप 2 तरह से declare िर सिते है।
 Using #define
 Using Const keyword
26 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
Using #define
#define एि pre-processor है इसे यूज़ िरिे आप constant declare िर सिते है।
इसिा उदाहरर् ननचे ददया जा रहा है।
# include <stdio.h>
#define result 10
int main()
{
int a=5, b=6;
result = a + b; /* WRONG, (ERROR) Value of constant result
variable can not be changed. */
printf("%d", result);
return 0;
}
ऊपर ददया गया program ननचे ददया गया output generate िरता है।
error : lvalue required as left operand of assignment
result = a + b;
^
Using const keyword
Const keyword िे द्वारा भी आप constants declare िर सिते है। इसिा उदाहरर्
ननचे ददया जा रहा है।
#include <stdio.h>
int main()
{
const int a=5;
const int b=6;
int c;
c = a+b;
27 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
printf("Result is : %d",a);
return 0;
}
ऊपर ददया गया program ननचे ददया गया output generate िरता है।
Result is : 11
28 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
C Flow Charts
 Introduction to flow chart in Hindi
 Symbols of flow chart in Hindi
 Examples of flow chart in Hindi
Introduction to Flow Chart
Flow chart किसी process िा graphical representation होता है। C language िे
सन्दभफ में यह program िे execution flow िा graphical presentation होता है।
प्रायः जब भी आप िोई program सलखते है तो बबना किसी flow chart िे सलखते है।
किसी दूसरे व्यजक्त द्वारा इसे समझना असींभव होता है। Flow chart िे माध्यम से आप
अपने program िो graphically represent िरते है। ऐसा िरने से िोई भी आपिे
program िे logic िो आपिे बबना भी समझ सिता है।
जब आप किसी company िे सलए programmer िे रूप में िाम िरते है तो coding से
पहले flow chart बनाना अननवायफ होता है। ऐसा इससलए किया जाता है क्योंकि
companies में अक्सर programmers बदलते रहते है। आपिे द्वारा बनाये गए किसी
project िो िोई दूसरा व्यजक्त आसानी से समझ सिे और उस पर िाम िर सिे इससलए
आपिो flow charts create िरना अननवायफ होता है।
Flow chart create िरने िा एि महत्वपूर्फ िारर् ये है िी इससे आपिो program िी
गहरी समझ प्राप्त होती है। आप coding से पहले ही उसमे आने वाली errors और result
िो देख पाते है। यदद flow chart completly prepare िर सलया गया है तो coding
ससर्फ एि simple process रह जाती है जजसमे programmer िो flow chart िे
अनुसार code सलखना होता है।
Flow chart िी सबसे बडी ववशेषता ये होती है िी flow chart किसी ववशेष
programming language िे सलए नहीीं होता है। Flow chart िो देखिर आप किसी भी
programming language में process िो implement िर सिते है।
बडी companies project develop िरने से पहले flow chart पर बहुत सा समय
लगाती है। Flow chart आपिे program िा blue print होता है। ये मिान बनाने से
पहले उसिा नक्शा बनाने जैसा होता है। जजतना समय coding में लगता है उससे िई
अधधि समय flow chart में लगाया जाता है। Algorithms भी flow chart िे अनुसार ही
बनायीीं जाती है।
हर अच्छे programmer िो इसे सीखना चादहए क्योंकि यह एि बहुत ही powerful tool
है। आज िल बहुत से modern text editors जैसे िी Microsoft word आदद flow
29 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
chart create िरने िे सलए built in options provide िरते है। आप इन्हें यूज़ िरिे
भी flow charts create िर सिते है।
Symbols of Flow Chart
किसी program िो graphically समझाने िे सलए िु छ symbols िा प्रयोग किया जाता
है। ये symbols आपिो पहले से provide किये गए है। इन्हें flow chart symbols िहा
जाता है। हर symbol िा एि मतलब होता है जजससे flow chart देखने वाला आसानी से
उसे समझ सिता है। ननचे आपिो table िे माध्यम से flow chart symbols िे बारे में
बताया जा रहा है।
Name Symbol Explanation
Begin/End
ये oval symbol होता है। इसे
terminal symbol भी िहा जाता
है। इसे flow chart िो start
और end िरने िे सलए यूज़
किया जाता है। किसी भी
processing से पहले program
िा start और end point
define िरना अत्यींत आवकयि है।
Processing
जब भी आप िोई execution
िरते है या कर्र िोई ऐसा
statement जजसमे processing
हो रही है उसे processing
symbol से दशाफया जाता है।
Input/Output
Program िे input और output
िो दशाफने िे सलए आप
parallelogram िा इस्तेमाल
िरते है।
Decision
Program िे decision making
statements िो दशाफने िे सलए
diamond symbol यूज़ किया
जाता है।
Arrow (Flow)
Program िा flow ददखाने िे
सलए arrow symbol यूज़ किया
जाता है। इसे हर symbol िे
बाद flow ददखाने िे सलए यूज़
किया जाता है।
30 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
Example of Flow Chart
मान लीजजये आप एि addition िा program बनाना चाहते है जो user से 2 numbers
read िरता है और उन्हें add िरिे result display िरता है।इसिे सलए आप flow
chart इस प्रिार बनाएींगे।
ऊपर ददए गए flow chart में सबसे पहले oval symbol से flow chart िो start किया
गया है। इसिे बाद rectangle symbol िे द्वारा 3 variables (num1, num2 और
Result) declare किये गए है। इसिे बाद parallelogram द्वारा num1 और num2 िो
read िरने िी process िो दशाफया गया है। इसिे बाद वापस rectangle symbol िे
द्वारा दोनों numbers िे addition और Result variable िो assign िरने िी
process िो दशाफया गया है। इसिे बाद parallelogram द्वारा result िो display िरने
िी process िो दशाफया गया है। सबसे आखखर में terminal symbol द्वारा flowchart
िो stop किया गया है। इस flow chart िो देखिर िोई भी व्यजक्त आसानी से addition
िे program िो किसी भी language में बना सिता है।
आइये flow chart िा एि और उदाहरर् देखते है। मान लीजजये आप एि program
बनाना चाहते है जो दो integer numbers िो read िरता है और जो उनमें से greater
हो उसे display िरवाता है। इसिे सलए flow chart इस प्रिार create किया जायेगा।
31 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
ऊपर ददए flow chart में सब िु छ पहले िी तरह ही है बस diamond symbol िे द्वारा
condition िे according दोनों numbers में से जो number greater है उसे display
किया जा रहा है।
32 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
First C program
 C program development life cycle in Hindi
 Structure of a C program
 Your First C program explained in Hindi
C program development life cycle
C में िोई भी program create िरने िे 4 steps हो सिते है। ये steps एि
particular order में होते है और इनिा अपना िु छ महत्व होता है। आइये पहला C
program create िरने से पहले इस process िो समझने िा प्रयास िरते है।
1. सबसे पहले आप एि program िो सलखते है। इसे program development life
cycle िा editing part भी िहते है। ये program human readable format
में होता है।
2. इसिे बाद आप program िो compile िरते हैं। ये development life cycle
िा second step होता है। इस part में सभी bugs िो remove िरिे
program िो binary format में convert किया जाता है ताकि computer इसे
process िर सिे ।
3. इसिे बाद linking process आती है। इस process में program िो necessary
libraries िे साथ link किया जाता है। जैसे िी आपिो पता है िी C िा basic
program भी बबना library िो include किये नहीीं execute हो सिता है।
Libraries C program िो execute होने िे सलए environment provide िरती
है।
4. इसिे बाद executable file produce िर दी जाती है। जजसे आप जजतनी बार चाहे
execute िर सिते है। Editing process िा output .c source file होती है।
Compiling process िा input source file होती है और output .obj files
33 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
होती है। Linking process िा input .obj file होती है और output .exe file
होती है।
Structure of A C program
Your first C program
#include <stdio.h>
int main()
{
printf("Hello Readers!");
return 0;
}
ऊपर ददया गया program ननचे ददया output generate िरता है।
Hello Readers!
सबसे पहली line में <stdio.h> header file िो program में include किया गया है।
ये एि standard input/output header file होती है जो program में input और
output िो handle िरती है। इन्हें pre processor directives भी िहते है।
34 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
इसिे बाद main() method िो start किया गया है। Main method से ही program
िा execution start होता है। इसी method में सभी instructions सलखे जाते है। Main
method िा start और end curly brackets िे द्वारा show किया जाता है। इन
curly brackets िे भीतर िे सभी instructions execute किये जाते है।
Main function िो int type िे साथ define किया गया है। ये एि standard है। Int
type िे बारे में आप आगे िी tutorials में जानेंगें। Main function िो एि integer
value return िरनी होती है। यदद आप program में main() function से िोई value
return नहीीं िरते है तो program िे आखखर में return 0 statement define िरते
है।
Commenting
Comments आपिे program में वो text होता है जजसे compiler ignore िर देता है।
ये text बािी statements िी तरह execute नहीीं होता है। Comments program में
किसी statement िो या कर्र program िो define िरने िे सलए यूज़ किये जाते है।
C language में commenting िी general form नीचे दी जा रही है।
/* your comment text here */
आइये अब comments िे यूज़ िो एि उदाहरर् से समझने िा प्रयास िरते है।
/* This is a c program which shows Hello World message on execution
*/
#include <stdio.h>
int main() /* Main function starts from here*/
{
printf("Hello World!"); /* This statement will print Hello World
message */
return 0;
}
जैसा िी आप ऊपर ददए गए program में देख सिते है, comments िे माध्यम से
program और दूसरे statements िे बारे में explanation दी गयी है। ये program
ननचे ददया गया output generate िरता है।
Hello World!
35 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
C Operators
 Introduction to C operators in Hindi
 Types of C operators in Hindi
 Arithmetic operators in Hindi
 Relational operators in Hindi
 Logical operators in Hindi
 Bit wise operators in Hindi
 Assignment operators in Hindi
 Conditional operator in Hindi
 Increment/Decrements operators in Hindi
 Special C operators in Hindi
Introduction to C operators
Variables िे अींदर values store िरवािर आप उन variables पर िई प्रिार िे
operations perform िर सिते है। उदहारर् िे सलए दो integer variables िे अींदर
value store िरवािर आप addition िा operation perform िर सिते है और उन
दोनों variables िी values िे sum िो print िरवा सिते है। इसी प्रिार आप और भी
अलग अलग operations variables िे साथ perform िर सिते है।
Variables िे साथ operations perform िरने िे सलए आपिो अलग अलग operators
यूज़ िरने पडते है। इस chapter में आपिो ऐसे ही operators िे बारे में बताया जा रहा
है।
Operations में operators िे साथ जो variables यूज़ होते है वो operand िहलाते है।
उदाहरर् िे सलए नीचे ददए गए statement िो देखखये।
c = a + b;
उपर ददए गए statement में a और b िो operator (+) िे साथ यूज़ किया गया है
इससलए ये दोनों variables operands िहलायेंगे।
Operators 2 प्रिार िे होते है।
 Unary - इस प्रिार िे operators ससर्फ एि ही operand िे साथ यूज़ किये
जाते है।
 Binary - इस प्रिार िे operators िे साथ 2 operands यूज़ किये जाते है।
आइये अब C language में यूज़ होने वाले अलग अलग operators िे बारे में जानने िा
प्रयास िरते है।
36 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
Arithmetic operators
Arithmetic operator mathematical operations perform िरने िे सलए यूज़ किये
जाते है। जैसे िी addition, subtraction, division और multiplication आदद।
Arithmetic operators 5 प्रिार िे होते है। ये basic mathematical operator होते
है।
Operators Description
+ (Addition) ये operator दो variables िी values िो add िरता है।
- (Subtraction) ये operator एि variable िी value में से दूसरे variable िी
value subtract िरता है।
* (Multiplication) ये operator 2 variables िी values िो multiply िरता है।
/ (Division) ये operator एि variable िी value से दूसरे variable िी
value िो divide िरता है।
% (Modulus) ये operator division िे बाद शेष बची हुई value िो प्राप्त
िरने िे सलए यूज़ किया जाता है।
Example
#include <stdio.h>
int main()
{
int a=10;
int b=5;
int c;
printf(“Value of a is : %dn”,a);
printf(“Value of b is : %dn”,b);
printf(“n”);
c = a + b; /* Addition operator */
printf(“Addition of a + b is : %dn”,c);
c = a - b; /* Subtraction operator */
printf(“Subtraction of a - b is :%dn”,c);
c = a * b; /* Multiplication operator */
printf(“Multiplication of a * b is : %dn”,c);
c = a / b; /* Division operator */
printf(“Division of a / b is : %dn”,c);
c = a % b; /* Modulus operator */
printf(“Modulus is of a is : %dn”,c);
37 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
return 0;
}
ऊपर ददया गया program ननचे ददया output generate िरता है।
Value of a is : 10
Value of b is : 5
Addition of a + b is : 15
Subtraction of a – b is : 5
Multiplication of a * b is : 50;
Division of a / b is : 2
Modulus of a % b is : 0
Relational operators
Relational operators दो variables िी values िो compare िरने िे सलए यूज़ किये
जाते है। जैसे िी आप इन operators िा यूज़ िरिे पता लगा सिते है िी क्या किन्ही
दो variables िी values बराबर है और यदद बराबर नहीीं है तो िौनसे variable िी
value बडी है और िौनसे variable िी value छोटी है।
इस तरह िे operators िो conditional statements (if,if-else,switch,for,while
आदद) िे साथ यूज़ किया जाता है। ये operators condition check िरने िे सलए यूज़
किये जाते है। Condition true होने पर value true हो जाती है और condition false
होने पर value false हो जाती है।
C language में यूज़ होने वाले सभी relational operators िे बारे में नीचे ददया जा रहा
है।
Operators Descriptions
== (Equal To) ये operator check िरता है िी क्या दोनों variables िी
values equal है।
!= (Not Equal
To)
ये operator check िरता है िी क्या दोनों variables िी
values non equal है।
< (Lesser Than) ये operator check िरता है िी क्या left operand िी value
right operand से छोटी है।
> (Greater Than) ये operator check िरता है िी क्या left operand िी value
right operand से बडी है।
<= (Lesser than
equal)
ये operator check िरता है िी क्या left operand िी value
right operand से छोटी या उसिे समान है।
>= (Greater ये operator check िरता है िी क्या left operand िी value
38 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
than equal) right operand से बडी या उसिे समान है।
Example
#include <stdio.h>
int main()
{
int a = 10;
int b = 5;
int c;
printf("Value of a is : %dn", 10);
printf("Value of b is : %dn",5);
printf("Are a & b equal ? : "); /* Equals to operator */
if(a == b)
{
printf("TRUEn");
}
else
{
printf("FALSEn");
}
printf("Are a & b are not equal ? :"); /* Not equals to operator */
if(a!=b)
{
printf("TRUEn");
}
else
{
printf("FALSEn");
}
printf("Is a less than b ? :"); /* Less than operator */
if(a < b)
{
printf("TRUE n");
}
else
{
printf("FALSE n");
}
printf("Is a greater than b ? : "); /*Greater than operator */
if(a > b)
{
printf("TRUEn");
}
else
{
39 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
printf("FALSEn");
}
printf("Is a less than equal to b ? :"); /* Less than equal operator */
if(a <= b)
{
printf("TRUEn");
}
else
{
printf("FALSEn");
}
printf("Is a greater than equal to b ?"); /*Greater than equal operator */
if(a >= b)
{
printf("TRUE");
}
else
{
printf("FALSE");
}
return 0;
}
ऊपर ददया गया program ननचे ददया output generate िरता है।
Value of a is : 10
Value of b is : 5
Are a & b equal ? : FALSE
Are a & b are not equal ? :TRUE
Is a less than b ? :FALSE
Is a greater than b ? : TRUE
Is a less than equal to b ? :FALSE
Is a greater than equal to b ?TRUE
Logical operators
Logical operators िो decision making statements िे साथ यूज़ किया जाता है। ये
operators control statements में एि साथ दो condition िो check िरने िे सलए
यूज़ किये जाते है। उदाहरर् िे सलए आप किसी if statement में एि िी जगह 2
conditions check िर सिते है। Logical operators िे बारे में नीचे ददया जा रहा है।
Operators Description
&& (AND) जब दोनों conditions true होती है तब control statement िी
40 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
value true हो जाती है।
|| (OR) जब िोई भी एि condition true हो तो भी control statement
िी value true हो जाती है।
! (NOT) ये operator एि ही condition िे साथ यूज़ किया जाता है। जब
वो condition false होती है तो control statement िी value
true हो जाती है।
Example
#include <stdio.h>
int main()
{
int a = 4;
int b = 10;
printf("Value of a is :%dn",a);
printf("Value of b is :%dn",b);
printf("Are both a & b greater than 5? :"); /* && AND operator */
if( a >5 && b >5)
{
printf("TRUEn");
}
else
{
printf("FALSEn");
}
printf("Is either a or b greater than 5? : "); /* || OR operator */
if( a > 5 || b > 5)
{
printf("TRUEn");
}
else
{
printf("FALSEn");
}
printf("Is a not equal to b?"); /* ! NOT operator */
if(!(a==b))
{
printf("TRUE");
}
else
{
printf("FALSE");
}
41 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
return 0;
}
ऊपर ददया गया program ननचे ददया output generate िरता है।
Value of a is :4
Value of b is :10
Are both a & b greater than 5? :FALSE
Is either a or b greater than 5? : TRUE
Is a not equal to b?TRUE
Bit wise operators
Bit wise operators ददए गए variables पर bit level operations perform िरने िे
सलए यूज़ किये जाते है। Variables िी decimal values bits में convert िी जाती है।
इसिे बाद उन bits पर operations perform किये जाते है।
C language में यूज़ होने वाले bit wise operators िे बारे में नीचे ददया जा रहा है।
Operators Description
& (Bit wise AND) इस operator िे द्वारा दोनों variables
िी same position वाली bits िे साथ
AND operation perform किया जाता है।
| (Bit wise OR) इस operator िे द्वारा दोनों variables
िी same position वाली bits िे साथ
OR operation perform किया जाता है।
~ (Bit wise NOT) ये operator ससर्फ एि ही operand िे
साथ यूज़ किया जाता है। जजस variable िे
साथ इसे यूज़ किया जाता है उस variable
िी value िी सभी bits opposite हो
जाती है। जैसे िी 0 है तो 1 हो जाती है
और 1 है तो zero हो जाती है।
^ (XOR) ये एि special type िा OR operator
होता है। ये operator opposite bits होने
पर 1 return िरता है और same bits
होने पर 0 return िरता है।
<< (Left Shift) ये operator left side िे variable िी
bits िो right side िे variable में दी
42 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
गयी value जजतना left में shift िरता है।
>> (Right Shift) ये operator left side िे variables िी
bits िो right side िे variable में दी
गयी value जजतना right में shift िरता
है।
जैसा िी आपिो पता है bit wise operators bits िे साथ work िरते है। मान लीजजये
आपने program में 2 variables a और b create किये हुए है। इन दोनों variables में
आपने क्रमशः 3 और 5 values store िरवाई हुई है। इनिी bits पर work िरने िे
सलए सबसे पहले आप इन्हें binary में convert िर सिते है।
3 = 00000011
5 = 00000101
ससर्फ आपिो समझाने िे purpose से इन्हें binary में convert किया गया है। आपिो
program में binary values insert िरवाने िी आवकयिता नहीीं है। Computer
information िो binary form में ही store िरता है। ऊपर define किये गए सभी
operations इन bits पर ही perform किये जायेंगे।
Example
#include <stdio.h>
int main()
{
int a = 3;
int b = 5;
int c;
c = a & b;
printf("Result of a & b is : %dn",c);
c= a|b;
printf("Result of a|b is : %dn",c);
c = ~a;
printf("Result of ~a : %dn",c);
c = a ^ b;
printf("Result of a ^ b is : %dn",c);
c= a<<4;
printf("Result of shifting a left by 4 places is : %dn",c);
c=a>>4;
printf("Result of shifting a right by 4 places is :%dn",c);
return 0;
43 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
}
ऊपर ददया गया program ननचे ददया output generate िरता है।
Result of a & b is : 1
Result of a|b is : 7
Result of ~a : -4
Result of a ^ b is : 6
Result of shifting a left by 4 places is : 48
Result of shifting a right by 4 places is :0
Assignment operators
Assignment operator variables िी values िो एि दूसरे िो assign िरने िे सलए
यूज़ किये जाते है। C language में यूज़ होने वाले ववसभन्न assignment operators िे
बारे में नीचे ददया जा रहा है।
Operators Description
= ये operator right side िे operand िी value िो left
side िे operand िो assign िरता है।
+= ये operator left side िे operand में right side िे
operand िी value िो add िरिे result left side वाले
operand िो assign िरता है। इसे आप इस प्रिार भी सलख
सिते है। a = a+b;
-= ये operator left side िे operand िी value में से right
side िे operand िी value िो subtract िरिे result left
side िे variable में store िरवाता है। इसे आप इस प्रिार भी
सलख सिते है। a=a-b;
*= ये operator left side िे operand िी value िो right
side िे operand िी value से multiply िरिे result िो
left side िे operand में store िरता है।
/= ये operator left operand िी value िो right operand िी
value से divide िरिे result िो left side िे operand में
store िरता है।
%= ये operator left side िे operand िी value िो right
side िे operand िी value से divide िरिे शेष बचे हुए
result िो left side िे operand में store िरता है।
44 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
Example
#include <stdio.h>
int main()
{
int a;
int b = 5;
a = b;
printf("Result of a = b is : %d",a);
a+=b;
printf("Result of a+=b is : %d ",a);
a-=b;
printf("Result of a-=b is : %dn",a);
a*=b;
printf("Result of a*=b is : %d",a);
a/=b;
printf("Result of a/=b is : %d",a);
a%=b;
printf("Result of a%=b is: %d",a);
return 0;
}
ऊपर ददया गया program ननचे ददया output generate िरता है।
Result of a = b is : 5
Result of a+=b is : 10
Result of a-=b is : 5
Result of a*=b is : 25
Result of a/=b is : 5
Result of a%=b is: 0
Increment/Decrements operators
किसी भी variable िी value िो एि number से instantly increase या decrease
िरने िे सलए आप increment/ decrements operators यूज़ िर सिते है। इनिे बारे
में नीचे ददया जा रहा है।
Operators Description
++ (increment) ये एि unary operator होता है। ये operand िी value िो
45 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
एि number से increase िरता है। जब यह operand िे पहले
लगता है तो value पहले increment होती है और बाद में यूज़
िी जाती है। जब ये operator operand िे बाद लगता है तो
operand िी value यूज़ होने िे बाद increment होती है।
--(decrements) ये भी एि unary operator होता है। ये operand िी value िो
एि number से decrease िरता है। जब इसे operand से पहले
यूज़ किया जाता है तो value यूज़ होने से पहले decrease होती
है। जब इसे variable िे बाद यूज़ किया जाता है तो value पहले
यूज़ होती है और बाद में decrease होती है।
Conditional (?:) operator
Conditional operator िो ternary operator भी िहा जाता है। ये if-else statement
िी short form होती है। इसिा general structure इस प्रिार होता है।
contion ? stmnt1 : stmnt 2;
यदद condition true हो तो statement one return होगा नही तो statement 2
return होगा। इसिा उदाहरर् ननचे ददया जा रहा है।
5>3 ? true : false;
Special C operators
Operators Description
sizeof (var_name
)
ये operator memory में variables िी size return िरता है।
& ये operator variables िा memory address return िरता
है।
* ये operator variable िा pointer return िरता है।
46 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
C Decision Making
 Introduction to C decision making in Hindi
 C If statement in Hindi
 C If else statement in Hindi
 C switch statement in Hindi
Introduction to C decision making
आप अपने program में िौनसे statements िो execute िरना चाहते है और िौनसे
statements िो skip िरना चाहते है ये आप खुद decide िर सिते है। इसे decision
making िहते है। ज्यादातर decision making किसी condition िे base पर िी जाती
है।
एि particular condition आने पर आप मनचाहे statements िो execute िर सिते
है। इसिे सलए आप िु छ built in statements िो यूज़ िरते है। क्योंकि ये statements
conditions िे साथ िाम िरते है इससलए इन्हें conditional statement भी िहा जाता
है। और क्योंकि ये statement program में execution िो control िरते है इससलए
इन्हें control statements भी िहा जाता है।
इन statements िे बारे में जानने से पहले आइये decision making िो एि उदाहरर् से
समझने िा प्रयास िरते है।
मान लीजजये आप किन्हीीं दो students में से जजसिी age अधधि हो उसिा नाम print
िरना चाहते है। आप ऐसा किस प्रिार िर सिते है? नीचे ददए हुए program िो देखखये।
#include <stdio.h>
#include <conio.h>
void main()
{
raviAge = 40;
ankitAge = 32;
}
उपर ददए गए उदाहरर् में 2 students िी age 2 variables में store िी गयी है।
लेकिन आपिो ससर्फ उसी student िी age print िरनी है जजसिी age सबसे ज्यादा हो।
इस situation में आपिो decision लेने िी आवकयिता है। ऐसा आप किसी भी decision
making statement (If, If-else, Switch) िे द्वारा िर सिते है।
47 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
आइये इन statements िे बारे में detail से जानने िा प्रयास िरते है।
If statement
If statement िा general syntax ननचे ददया जा रहा है।
if(condition)
{
// statements
}
If statement curly braces {} िे द्वारा एि block define िरता है। जब
condition true होती है तो इस block में ददए गए statement execute होते है। यदद
condition false हो तो इस पुरे block िो compiler skip िर देता है। यदद उपर ददए
गए example में if statement िा यूज़ किया जाये तो program िो इस प्रिार सलखा
जा सिता है।
#include <stdio.h>
int main()
{
int raviAge = 40;
int ankitAge = 32;
if(raviAge > ankitAge)
{
printf("Ravi is elder.");
}
return 0;
}
उपर ददए गए उदाहरर् में conditional operator िा यूज़ िरते हुए एि condition
लगायी गयी है। यदद Ravi िी age Ankit से अधधि है तो if statement में ददया गया
printf() statement execute होगा है। लेकिन यदद ऐसा नहीीं है तो ये statement
execute नहीीं होगा। ये program ननचे ददया गया output generate िरेगा।
Ravi is elder.
48 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
If-Else statement
If else statement िो if statement िा ही part माना जाता है। लेकिन इसमें else
block और add किया जाता है। Else block में ददए गए statement तब execute होते
है जब if िी condition false हो जाती है। If-else statement िा general syntax
नीचे ददया जा रहा है।
if(condition)
{
//statements
}
else
{
//statements
}
जैसा िी आपिो पता है if िी condition true होने पर if block में ददए गए
statements execute होते है। लेकिन आप ये भी decide िर सिते है िी यदद
condition false हो तो क्या किया जाना चादहए। इसिे सलए आप else block यूज़ िरते
है। ये block हमेशा if block िे बाद में आता है। इस block में वो statements सलखे
जाते है जो िी condition false होने पर execute होंगे। यदद ऊपर ददए गए उदाहरर् में
if else statement िा प्रयोग किया जाये तो आप उसे इस प्रिार सलख सिते है।
#include <stdio.h>
void main()
{
int raviAge = 20;
int ankitAge = 32;
if(raviAge > ankitAge)
{
printf("Ravi is elder");
}
else
{
printf("Ankit is elder");
}
}
ऊपर ददया गया program ननचे ददया गया output generate िरता है।
Ankit is elder.
49 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
else if
यदद आप if और else िे बीच में एि और condition लगाना चाहते है तो ऐसा आप
else if block define िरिे िर सिते है।
if(raviAge > ankitAge)
{
printf("Ravi is elder");
}
else if(ankitAge > raviAge)
{
printf("Ankit is elder");
}
else
{
printf("Both are equal");
}
Switch statement
Switch statement भी if statement िी तरह ही होता है लेकिन इसमें condition
check िरने िी बजाय case check किया जाता है। एि particular case आने पर आप
जो statements execute िरना चाहते है उन्हें आप case िे अींदर सलखते है।
Case एि integer variable से match किया जाता है। जो case integer variable से
match हो जाता है वही case execute हो जाता है
Switch statement िा general syntax नीचे ददया जा रहा है।
int caseNumber = n;
switch(caseNumber)
{
case 1:
//statements to be executed
break;
case 2:
//statements to be executed
break;
default:
//statements to be executed
50 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
break;
}
जब आप caseNumber variable िो किसी integer value िे साथ set िरते है और
इसे switch statement में pass िरते है तो ये number जजस caseNumber से
match िरेगा वही case execute होगा।
जैसे िी यदद आपने case number में 2 pass किया है तो second number िा case
execute होगा और break से पहले िे सभी statements execute हो जायेंगे।
यदद िोई case match नहीीं िरता है तो default case execute होता है। यदद हर
case िे बाद break statement ना यूज़ किया जाये तो सभी case execute हो जाएींगे।
Case िो आप alphabets से भी define िर सिते है।
आइये switch statement िो एि उदाहरर् िे माध्यम से समझने िा प्रयास िरते है।
#include <stdio.h>
void main()
{
int caseNumber;
printf("Enter a number ");
scanf("%d",&caseNumber);
switch(caseNumber)
{
case 1:
printf("nFirst Case executed....");
break;
case 2:
printf("nSecond Case executed....");
break;
default:
printf("nNone of the case matched. You can only
enter 1 or 2");
break;
}
}
51 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m
उपर ददए गए उदाहरर् में user से एि number enter िरवाया जा रहा है और उस
number िे base पर matching case execute िरवाया जा रहा है। ये program ननचे
ददया गया output generate िरता है।
Enter a number :
2
Second case executed....
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf
C pdf

Mais conteúdo relacionado

Destaque

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Destaque (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

C pdf

  • 1.
  • 2. [i] Copyright & Disclaimer  Copyright 2017 by www.besthinditutorials.com. All the content and graphics published in this e-book are the property of www.besthinditutorials.com. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. www.besthinditutorials.com provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at contact@besthinditutorials.com https://www.facebook.com/besthinditutorials https://twitter.com/BH_Tutorials https://plus.google.com/+Besthinditutorialscom
  • 3. [ii] Table of Contents .................................................................................................................................1What is Programming? Introduction to Programming..............................................................................................................1 Programming Language............................................................................................................................1 Compiler / Interpreter.............................................................................................................................3 Programmer ......................................................................................................................................................3 ...................................................................................................................................4Basics of C Language Introduction to C language..................................................................................................................4 A simple program in C language.................................................................................................6 ................................................................................................................................7C Compiler Installation Introduction to Dev C++ Compiler ................................................................................................7 Installing Dev C++ compiler...............................................................................................................7 Working with Dev C++ compiler...................................................................................................12 ....................................................................................................16C Tokens, Identifiers & Keywords Introduction to C Tokens.....................................................................................................................16 C Character Set...........................................................................................................................................17 Identifiers.........................................................................................................................................................17 Keywords ..........................................................................................................................................................18 .....................................................................................................................................................19C Data Types Introduction to C Data Types ..........................................................................................................19 Different C data types ...........................................................................................................................19 Void type..........................................................................................................................................................21 ...........................................................................................................................22C Variables & Constants Introduction to C variables ................................................................................................................22 Scope of variables.....................................................................................................................................24 Constants in C..............................................................................................................................................25 ...................................................................................................................................................28C Flow Charts Introduction to Flow Chart.................................................................................................................28
  • 4. [iii] Symbols of Flow Chart ..........................................................................................................................29 Example of Flow Chart..........................................................................................................................30 ...............................................................................................................................................32First C program C program development life cycle ................................................................................................32 Structure of A C program...................................................................................................................33 Your first C program...............................................................................................................................33 Commenting ....................................................................................................................................................34 .........................................................................................................................................................35C Operators Introduction to C operators...............................................................................................................35 .........................................................................................................................................46C Decision Making Introduction to C decision making...............................................................................................46 If statement...................................................................................................................................................47 If-Else statement........................................................................................................................................48 Switch statement........................................................................................................................................49 .............................................................................................................................................................52C Looping Introduction to C language looping.............................................................................................52 C while loop ..................................................................................................................................................53 C Do-while loop ..........................................................................................................................................54 C For loop .......................................................................................................................................................55 ................................................................................................................................................................56C Arrays Introduction to C arrays ......................................................................................................................56 Creating c arrays........................................................................................................................................56 Initializing C arrays..................................................................................................................................57 Accessing array elements.....................................................................................................................58 Two Dimensional Arrays .......................................................................................................................59 ...............................................................................................................................................................63C Strings Introduction to C strings .....................................................................................................................63 gets() and puts() functions ...............................................................................................................64
  • 5. [iv] Other string functions ............................................................................................................................65 .........................................................................................................................................................66C Functions Introduction to C functions................................................................................................................66 Predefined & user defined functions ..........................................................................................66 Advantages of functions........................................................................................................................67 Creating & using functions in C ....................................................................................................67 Example .............................................................................................................................................................70 .......................................................................................................................................................71C Structures Introduction to C structures..............................................................................................................71 Defining a structure.................................................................................................................................71 Creating structure variables...............................................................................................................72 Accessing structure members ...........................................................................................................73 Example .............................................................................................................................................................73 ...............................................................................................................................................................75C Unions Introduction to C unions.................................................................................................................75 .........................................................................................................................................................78C Recursion Introduction to C Recursion ..............................................................................................................78 Types of Recursion ...................................................................................................................................79 Example of Recursion (Factorial).......................................................................................................80 ............................................................................................................................................................83C Pointers Introduction to C pointers..................................................................................................................83 Working with pointers............................................................................................................................84 Example .............................................................................................................................................................85 ..........................................................................................................................................87C Storage Classes Introduction to C storage classes.................................................................................................87 ................................................................................................................................................91C File Handling Introduction to C file handling .......................................................................................................91 Opening a file...............................................................................................................................................91
  • 6. [v] Reading from a file..................................................................................................................................93 Writing to a file .........................................................................................................................................94 Closing a file.................................................................................................................................................94 .............................................................................................................................................95C Error Handling Introduction to C error handling...................................................................................................95 exit() function...............................................................................................................................................97 ..................................................................................................................................................98C Header Files Introduction to C header files.........................................................................................................98 Types of header files..............................................................................................................................98 Working with header files...................................................................................................................99 ....................................................................................................................101C Preprocessors Directives Introduction to C preprocessor directives.............................................................................101
  • 7. 1 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m What is Programming?  Introduction to programming in Hindi  Programming language in Hindi  What is Compiler in Hindi  Who is Programmer in Hindi Introduction to Programming India में हर साल लाखों students computer scientists बनते है। हालााँकि एि computer scientist ससर्फ programming ही नहीीं िरता है, लेकिन programming computer science िा बहुत ही महत्वपूर्फ part है। इससलए एि शुरआती programmer होने िे नाते आपिे सलए programming और उससे related components िा concept ठीि से समझना बहुत जरुरी है। कितने ही ऐसे programmers होते है जो programming तो िर रहे होते है लेकिन उनिो programming िे पीछे िा concept नहीीं पता होता है। आइये इसिे बारे में जानने िा प्रयास िरते है। आसान शब्दों में िहा जाये तो programming एि ऐसी process होती है जजसमें एि programmer CPU (Central Processing Unit) िो िोई task perform िरने िे instructions देता है। ये task िु छ भी हो सिता है जैसे िी दो numbers िो add िरना आदद। Programming िु छ components से समलिर एि समग्र रूप धारर् िरती है। 1. Programming Language 2. Compiler / Interpreter 3. Programmer इन components िे बारे में ननचे detail से बताया जा रहा है। Programming Language Humans जब भी interact िरते है तो किसी language िे माध्यम से िरते है। एि CPU िो भी आप language िे माध्यम से ही instructions देते है। ऐसी language जो CPU िो instructions देने िे सलए programmers यूज़ िरते है programming language िहलाती है। CPU ससर्फ binary language (0 & 1) िो ही समझता है। लेकिन किसी भी human िे सलए binary language में programming िरना असींभव है। इससलए simple English sentences िो यूज़ िरते हुए programming languages develop िी गयी।
  • 8. 2 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m ऐसा िरने से programming िरना बहुत अधधि आसान हो गया। अब जैसा िी आप देख सिते है हर िोई basic information प्राप्त िरिे programming िरना ससख सिता है। लेकिन पहले ऐसा सींभव नहीीं था। Types of Programming Languages अब ति 256 से अधधि programming languages develop िी जा चुिी है। हर language िो एि different purpose िे सलए develop किया गया है। Purpose िे according programming languages िो mainly 5 categories में divide किया गया है। 1. Machine Language / Machine Code - ये वो code होता है जजसे CPU directly execute िरता है। Machine code hexadecimal में होता है। ये hardware िे बहुत ही िरीब होता है। इसे low level language भी िहा जाता है। 2. Assembly Language - Machine code िो और भी अधधि readable बनाने िे सलए assembly language create िी गयी। इसमें labels िो add किया गया है जजससे tasks perform िरना और भी आसान हो जाता है। ये भी एि low level language होती है। 3. High-Level Language - High level languages hardware से independent होती है जैसे िी c, c++, java आदद। इन languages िा code directly machine code में convert नहीीं होता है। 4. System Language - इस प्रिार िी languages computer िो manage िरने िे सलए यूज़ िी जाती है। इन्हें low level tasks perform िरने िे सलए यूज़ किया जाता है। जैसे िी memory management, procsess management आदद। 5. Scripting Languages - इस प्रिार िी languages system और दूसरी applications िे बीच में bridge िी तरह िाम िरती है। जैसे िी PHP आदद। Some Common Programming Languages याँहा पर िु छ programming languages िी list दी जा रही है। इनमें से िु छ िे बारे में आप सुन चुिे होंगे।  C Language  C++  Java  C#  PHP  HTML  JavaScript
  • 9. 3 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m  Pascal  Visual Basic  FORTRAN Compiler / Interpreter जैसा िी मैने आपिो बताया computer ससर्फ binary language समझता है और humans िा binary में programming िरना बहुत मुजकिल है। इससलए एि ऐसा program develop किया गया जो programmers से simple English statements िे रूप में instructions ले सिे और उसे binary में convert िरिे CPU िो pass िर दे। इस program िो compiler िहते है। Compiler एि programmer और CPU िे बीच bridge िी तरह िाम िरता है। इसे आप translator भी िह सिते है। एि compiler बहुत से tasks perform िरता है इनिे बारे में ननचे ददया जा रहा है।  Compiler syntax error check िरता है। यदद िोई syntax error होती है तो इसिे बारे में programmer िो notify किया जाता है।  Compiler source code िो machine language में convert िरता है।  Compiler एि machine executable file generate िरता है। आइये अब interpreter िे बारे में जानने िा प्रयास िरते है। िु छ languages compiler िी जगह interpreter भी use िरती है। Compiler और interpreter दोनों एि ही िाम िरते है। र्िफ ससर्फ इतना होता है िी compiler पुरे source code िो एि साथ compile िरिे machine code generate िरता है जजसे एि बारे में completely execute किया जा सिता है। जबकि एि interpreter एि एि instructions िो machine code में convert िरता है और साथ िी साथ execute िरता जाता है। अपनी need िे according languages compiler और interpreter िो यूज़ िरती है। Programmer शुरूआती ददनों में लोग interest िी वजह से programming िरते थे लेकिन अब इसने एि job िा रूप धारर् िर सलया है। Programmer वह person होता है जजसे िी किसी programming language िा ज्ञान होता है। एि programmer अपने ज्ञान िो यूज़ िरते हुए programming language िी मदद से real world problems िो solve िरता है।
  • 10. 4 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m Basics of C Language  Introduction to C in Hindi  Characteristics & Features of C in Hindi  Limitations of C in Hindi  Applications of C in Hindi  A simple C program Introduction to C language C एि बहुत ही popular programming language है। इसे Middle level language माना जाता है। आज भी C िी popularity में िोई िमी नहीीं आई है। किसी भी दूसरी language िो ससखने से पहले C िो सीखना बहुत जरुरी है। क्योंकि C िे बाद जजतनी भी programming languages आई उन्होंने किसी न किसी तरह C िे features िो adopt किया है। आइये C िे बारे में detail से जानने िा प्रयास िरते है। History C एि structured general purpose programming language है। इसे UNIX operating system िो दुबारा सलखने िे सलए develop किया गया था। इससे पहले UNIX operating system िो B language में सलखा गया था। पूरा UNIX operating system और उस पर run होने वाले ज्यादातर programs C language में ही सलखे गए है। B language Ken Thompson िे द्वारा 1970 में Bell laboratories में सलखी गई थी। B एि type less language थी। C language िो Dennis Ritchie ने 1972 में Bell laboratories में ही develop किया था। C language बहुत से data types provide िरती है। C language िे syntax िो बहुत सी popular languages ने follow किया है। C िा improved version C# है। C िे features िो Java और C++ जैसी languages ने follow किया है।
  • 11. 5 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m Characteristics & Features  C एि modular language है। C में एि बडे program िो छोटे छोटे modules (functions) िे रूप में divide किया जाता है। ऐसा िरने से programs िो manage और debug िरने में आसानी रहती है।  C एि flexible language है। C 32 reserved keywords provide िरती है। ये keywords programmer िो language पर control provide िरते है। इन keywords िी मदद से program िे structure िो भी modify किया जा सिता है।  C language Assembly language िे बाद सबसे fast language मानी जाती है। इसे िई बार low level language भी िहा जाता है। C language hardware िे बहुत िरीब होती हैं। इससलए ये दूसरी programming languages से fast होती है।  C एि case sensitive language है।  C High level और low level दोनों तरह िे programs create िरने में सक्षम है।  C एि extendable language है। C programs में libraries िे द्वारा आप िभी भी नए features add िर सिते है। Limitations  C language में run time type checking नहीीं होती है। C language run time में किसी भी variable िे data type िो identify िरने में असमथफ होती है। उदाहरर् िे सलए float data type में integer value डाली जा सिती है।  C language में object oriented concepts नहीीं होते है।  C language में constructors और destructors िा concept भी नहीीं होता है।  C language में namespaces िा concept नहीीं होता है। इससलए different programmers िे code िो एि ही project में यूज़ िरना बहुत मुजकिल होता है।  C language code िी re-usability िो support नहीीं िरती है।  C language में exceptions िो run time में handle नहीीं किया जा सिता है। Applications  ज्यादतर operating systems C language में ही बनाए जाते है। जैसे िी UNIX, Windows आदद।  किसी भी नयी programming language िो compile िरने िे सलए compilers िी आवकयिता होती है। C language में compilers भी create किये जाते है।
  • 12. 6 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m उदाहरर् िे सलए java िा compiler javac भी C language में ही बनाया गया है।  C language में िई प्रिार िे assemblers भी create किये जाते है। Assembler basic instructions िो bits में convert िरते है।  C language में text editors भी create किये जा सिते है। जैसे िी gedit, आदद।  C language में network drivers भी create किये जाते है।  C language में database systems भी सलखे जाते है। जैसे िी oracle database C में ही सलखा गया है। A simple program in C language #include <stdio.h> int main() { printf("Hello Readern"); return 0; } ऊपर ददया गया program ननचे ददया गया output generate िरता है। Hello Reader
  • 13. 7 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m C Compiler Installation  Introduction to Dev C++ compiler in Hindi  Installing Dev C++ compiler in Hindi  Working with Dev C++ compiler in Hindi Introduction to Dev C++ Compiler जैसा िी आपिो पता है एि compiler programmer द्वारा किसी programming language में सलखे गए code िो machine executable form में convert िरता है। C language िे सलए अलग अलग platforms िे अनुसार बहुत से compilers available है। Dev C++ एि (Integrated Development Environment) है। इसिे माध्यम से c या c++ में programming िरना बहुत ही आसान हो जाता है। ये IDE आपिो graphical user interface provide िरती है और साथ ही आपिो automatic code completion, syntax highlighting और एि साथ िई files िे साथ work िरने िी ability provide िरती है। Best Hindi Tutorials िे readers िे सलए इस ही IDE िो recommend किया जाता है। हालााँकि अभी भी िई university और colleges में Turbo C compiler िो use किया जा रहा है लेकिन ये IDE आपिो better development environment provide िरता है इससलए आपिो इसे ही use िरना चादहए। Installing Dev C++ compiler इस IDE िो आप Dev-C++ Download Page से download िर सिते है। इसे install िरना ननचे steps िे द्वारा समझाया जा रहा है। 1. जैसे ही आप setup.exe file िो download िरिे उस पर click िरेंगे तो आपिो ननचे दी गयी window show होगी।
  • 14. 8 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m ऊपर दी गयी window में आपिो अपनी preferred language select िरनी है। Default language English है। याँहा पर आप OK click िरेंगे। 2. इसिे बाद आपिो ननचे दी गयी screen show होगी। ये licence agreement िी window है। याँहा पर आप I Agree button पर click िरेंगे। 3. इसिे बाद आपिो ननचे दी गयी window show होगी। इस window में आपिो type of installation select िरना होता है। ये window आपिो 3 (Full, Typical और Custom) options provide िरती है। आप अपनी need िे according िोई भी installation type select िर सिते है। Installation type select िरने िे बाद आप next पर click िरेंगे। 4. इसिे बाद आपिो ननचे दी गयी window show होगी।
  • 15. 9 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m इस window में आप वह location बताते है जाँहा पर आप Dev C++ िो install िरना चाहते है। By default ये c drive में install होगा। Location set िरने िे बाद आप Install button पर click िरेंगे। 5. इसिे बाद आपिो ननचे दी गयी window show होगी। ये installation progress window है। इस window में आपिो िोई action नहीीं लेना है। 6. ऊपर दी गयी progress window िे complete होते ही आपिो ननचे दी गयी window show होगी।
  • 16. 10 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m ये completion window है याँहा पर आपिो Finish button पर click िरना होगा। 7. इसिे बाद आपिो ननचे दी गयी window show होगी। ये first time configuration window होती है। इस window में आप language और Dev c++ िी theme select िरते है। इसिे बाद आप next button पर click िरेंगे। 8. इसिे बाद आपिो ननचे दी गयी window show होगी।
  • 17. 11 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m इस window में आपसे पूछा जा जायेगा िी क्या आप Dev C++ िो Header files िे साथ use िरना चाहते है। याँहा पर आप Yes, I want to use this feature option िो select िरेंगे। 9. इसिे बाद आपिो ननचे दी गयी window show होगी। इस window में आपसे cache create िरने िे सलए पूछा जाएगा। इस window में आप Yes, create the cache option select िरेंगे। 10. इसिे बाद आपिो ननचे गयी window show होगी।
  • 18. 12 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m ये window आपिो बताती है िी Dev C++ िो successfully configure िर सलया गया है। इस window में आप OK button पर click िरेंगे। 11. इसिे बाद आपिो ननचे दी गयी window show होगी। ये Dev C++ िी window है। अब आपिे PC में Dev C++ successfully install हो चूिा है। Working with Dev C++ compiler याँहा पर मैं आपिो Dev C++ compiler में एि simple program बनािर उसे execute िरिे बता रहा हूाँ जजससे आप इसिे basic uses िो समझ पाएींगे। सबसे पहले आप Dev C++ compiler िो open िरेंगे। इसिे बाद आप एि नयी file create िरेंगे। नयी file create िरने िे सलए आप Menu bar में File option पर click िरेंगे और इसिे बाद new menu में जािर source file पर click िरेंगे। जैसा िी ननचे दी गयी window में show किया गया है।
  • 19. 13 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m जैसे ही आप Source File option पर click िरेंगे right side में editor open हो जायेगा। जैसा िी ननचे दी गयी image में show हो रहा है। याँहा पर आप अपना code सलखते है। जैसे िी ननचे गयी image में show हो रहा है।
  • 20. 14 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m Code सलखने िे बाद आप अपने program िो compile िरते है। इसिे सलए आप Execute menu में जािर compile option पर click िरते है। जैसा िी ननचे दी गयी image में ददखाया गया है। Compile option पर click िरते ही आपिो एि window show होगी जजसमे आपिो इस program िो save िरने िे सलए िहा जाएगा। जैसे िी ननचे दी गयी image में show हो रहा है। जैसे ही आप इस program िो किसी name िे साथ save िरते है program compile होना शुरू हो जाएगा। यदद program में िोई error है तो वह editor िे ननचे show होगी नहीीं तो program successfully compile हो जाएगा और done िा message show िरेगा।
  • 21. 15 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m Program िे compile होने िे बाद आप इसे run िरेंगे। Program िो run िरने िे सलए आप Execute menu में जािर run option पर click िरेंगे। इसिे बाद आपिा program run हो जाएगा और आपिो console window में output show होगा। जैसा िी ननचे दी गयी image में show हो रहा है।
  • 22. 16 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m C Tokens, Identifiers & Keywords  Introduction to C tokens in Hindi  C character set in Hindi  C Identifiers in Hindi  C keywords in Hindi Introduction to C Tokens C language िा syntax िई दूसरी popular languages िे द्वारा follow किया गया है, इससलए C िा syntax समझना आपिे सलए बहुत आवकयि है। C program tokens से समलिर बना होता है। जैसे िी ननचे ददए गए program िो देखखये। ये program tokens िा सही क्रम में यूज़ है और इसिे ससवा िु छ भी नहीीं है। यदद आप C िे सभी tokens िो यूज़ िरना ससख ले तो आप C िे expert बन जायेंगे। #include <stdio.h> int main() { printf("Software programming is cool"); print("%d",5); } Tokens 6 types िे होते है। इनिी list ननचे दी जा रही है।  Identifier  Keyword  Constant  Variable  String  Operator यदद इस list िे according आप देखें तो ऊपर ददए गए program में int, main, printf ,+ और Software programming is cool आदद सब िु छ tokens ही है। इनमें से सभी tokens िे बारे में अभी ना बतािर में याँहा पर आपिो ससर्फ Identifiers और keywords िे बारे में बताने जा रहा हूाँ। बाकि tokens िे बारे में आपिो आगे िी tutorials में बताया जायेगा। मै समझता हूाँ िी आपिो tokens क्या है ये concept clear हो गया होगा। अगर ऐसा है तो आइये िु छ tokens िे बारे में detail से जानने िा प्रयास िरते है। लेकिन इससे से पहले में आपिो C language िे character set िे बारे में बताने जा रहा हूाँ।
  • 23. 17 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m C Character Set C language में आप program characters िी sequence में सलखते है। जैसे िी #include <stdio.h> ये statement characters से ही बना है। याँहा पर i,n,c,l और h आदद characters है। लेकिन ऐसा नहीीं है िी आप C program में िोई भी character यूज़ िर सिते है। इसिे सलए C िे द्वारा character set define किया गया है। जो characters इस set में है िे वल वे ही एि C program में यूज़ किये जा सिते है। Alphabet Alphabet characters में आप A से Z upper case और a से z lower case characters िो यूज़ िर सिते है। Digits Digits में आप 0 से लेिर 9 ति िी िोई भी digits यूज़ िर सिते है। Special characters Special characters में आप ननचे ददए गए characters िो यूज़ िर सिते है। ! @ # $ % ^ & * ( ) _ - + = | { } [ ] < > ", ? / इन alphabet digits और special characters िे अलावा आप िोई और character C language में यूज़ नहीीं िर सिते है। इसे ही C िा character set िहते है। Identifiers Identifiers वो नाम होते है जो आप variables, constants और functions आदद िो देते है। इन नामों िो देने िे सलए भी िु छ ननयम है जो आप follow िरते है। यदद आप इन ननयमों िो follow नहीीं िरते है तो program में error आ जाती है। ये ननयम आगे बताये जा रहे है। 1. Identifiers में @, %, - characters allowed नहीीं है। 2. C case sensitive language है। इससलए age और Age 2 different identifiers है। 3. Identifiers में आप operators नहीीं यूज़ िर सिते है।
  • 24. 18 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m 4. Identifier िी शुरआत आप या तो character या underscore से िर सिते है। Digits से identifier िो start नहीीं किया जा सिता है। 5. आप A से लेिर Z ति िे small और capital दोनों तरह िे letters या कर्र underscore में से किसी िे साथ भी identifiers िो start िर सिते है। इसिे बाद आप digits और दूसरे characters या underscore यूज़ िर सिते है। Example _age // Valid 2name // Invalid Emp-name // Invalid Emp_2_age // Valid Keywords Keywords िो predefined tokens या reserved words भी िहते है। C language 32 keywords provide िरती है। हर keyword िा एि खास मतलब होता है। हर keyword िो एि particular task perform िरने िे सलए define किये गया है। इन keywords िी list ननचे दी जा रही है। इन keywords िो याँहा पर explain नहीीं किया जा रहा है। इनिे बारे में आप धीरे धीरे आगे आने वाली tutorials में जानेंगे। auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while
  • 25. 19 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m C Data Types  Introduction to C data types in Hindi  Different C data types in Hindi  Integer type in Hindi  Floating point type in Hindi  Char type in Hindi Introduction to C Data Types जब भी आप िोई variable create िरते है तो उससे पहले compiler िो बताते है िी आप किस तरह िा data उस variable में store िरेंगे। इससे compiler उतनी ही memory उस variable िो computer िी memory में से allot िर देता है। जैसे िी ननचे ददए गए statement िो देखखये। int age; ऊपर ददया गया statement compiler िो बताता है िी आप age variable में एि whole number store िरने वाले है। किसी भी whole number िो store िरने िे सलए जजतनी memory िी आवकयिता होती है compiler उतनी इस variable िो allot िर देता है। जो िी 2 bytes है। अब आप सोच सिते है िी यदद किसी programming language में data types ना हो तो कितनी memory waste हो सिती है। जाँहा पर 2 bytes िी requirement हो वाँहा 20 bytes आप waste िर सिते है। इस प्रिार जजतनी भी तरह िा data आप store िर सिते है उसिे सलए पहले से ही maximum memory limit define िी गई है। आइये अब C िे अलग अलग तरह िे data types िे बारे में जानने िा प्रयास िरते है। Different C data types C language 3 तरह िे data types िो support िरती है। इन्हें primitive types भी िहते है।  Integer o int o short int o long int o singed int o unsigned int  Floating point o float o double
  • 26. 20 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m  Character o char Integer Integer types किसी भी whole number (बबना दशमलव िे ) िो store िरने िे सलए यूज़ किये जाते है। Integer types 5 प्रिार िे होते है। हालाींकि ये सभी whole number िो store िरते है। लेकिन memory size और range िे base पर इन्हें categories किया गया है। Data type Size (Bytes) Range int 2 -32768 से 32767 short int 1 -128 से 127 long int 4 -2,147,483,648 से 2,147,483,647 signed int 2 -32768 - 32767 unsigned int 2 0 - 65535 Example long int population = 200000000; Floating point Floating point data types िो दशमलव सींख्याओीं िो store िरने िे सलए define किया गया है। Floating point data types 2 तरह िे होते है। इनिो size और range िे base पर categories किया गया है। Float type में आप दशमलव िे बाद 7 digits ति store िर सिते है। Double type में दशमलव िे बाद 17 digits ति store िी जा सिती है। Data types Size (Bytes) Range Float 4 3.4E-38 से 3.4E+38 Double 8 1.7E-308 से 1.7E+308 Example double balance=810.12354984;
  • 27. 21 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m Character Character type िो एि character store िरने िे सलए यूज़ किया जाता है। इनिो 2 categories में divide किया गया है। Data type Size (Bytes) Range char 1 -128 से 127 unsigned char 1 0 से 255 Example char bestlanguage = "C"; Void type Void type िो उन situations में यूज़ किया जाता है जब आपिो value िे बारे में िोई जानिारी ना हो। इसे functions िे साथ ज्यादातर यूज़ किया जाता है। C में void type िो आप इन situations में यूज़ िर सिते है। 1. यदद आपिा function िोई value return नहीीं िरता है तो आप उसिा return type void define िरते है। उदाहरर् िे सलए आप इस प्रिार function define िर सिते है। void myFunction();। 2. यदद आप function में िोई parameters नहीीं ले रहे है तो आप वाँहा पर void define िर सिते है। Void type से पता चलता है िी इस function में िोई argument नहीीं सलया जाता है। उदाहरर् िे सलए आप इस प्रिार void िो parameter िे रूप में pass िर सिते है। int myFunction(void);। 3. यदद आप sure नहीीं है िी pointer variable किस type िे variable िो point िरेगा तो आप उसिा type void declare िर सिते है। इसिे बाद आप void pointer से किसी भी variable िो point िर सिते है।
  • 28. 22 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m C Variables & Constants  Introduction to C variables in Hindi  Creating C variables in Hindi  Scope of C variables in Hindi  Introduction to C constants in Hindi Introduction to C variables यदद आप computer िी memory में data िो store िरना चाहते है तो इसिे सलए पहले आपिो उस memory location िे सलए नाम देना होता है। Variable memory में किसी location िा नाम होता है। मान लीजजए ये आपिा computer memory space है। आप इसमें िु छ data store िरवाना चाहते है। जैसे िी किसी व्यजक्त िी उम्र आदद। Computer िी memory में data store िरवाने से पहले आप बताते ही िी आप किस तरह िा data store िरेंगे। ये आप data types िे द्वारा define िरते है। उसी िे according आपिो memory में space समलता है। यानन िी यदद आपने int define किया है तो 2 bytes आपिो memory में compiler allot िरेगा। इसिे साथ ही आपिो उस memory location िा नाम भी define िरना होता है। ताकि आप जब भी चाहे उस memory location में store िी गई value िो इस नाम िे द्वारा access िर सिे । इस नाम िो ही variable िहते है। Variables िी values changeable होती है। आप एि value िो हटािर दूसरी value डाल सिते है। ऐसा आप manually खुद भी िर सिते है या कर्र dynamically (program execution िे दौरान) भी िर सिते है।
  • 29. 23 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m Creating variables in C Variables create िरने िे सलए सबसे पहले आप data type define िरते है। इसिे बाद आप एि unique name define िरते है। इसिा structure इस प्रिार होता है। dataType variableName; // without assigning value dataType variableName = value; // with value assignment उदाहरर् िे सलए ननचे ददए गए statement िो देखखये। int Age = 25; इस statement िे द्वारा एि integer variable create किया गया है, जजसिा नाम Age है और इस variable िो 25 value assign िी गई है। आइये अब समझते है िी compiler इस statement िो किस प्रिार interpret िरता है। जब compiler सबसे पहले int िो interpret िरता है तो वह computer िी memory में से 2 bytes िी memory allot िरता है। इसिे बाद जब compiler Age िो interpret िरता है तो वह उस 2 bytes िी memory िो age नाम दे देता है। इसिे बाद जब compiler = 25 िो interpret िरता है तो 25 िो इस memory location store िर देता है। अब जब भी आप इस value िो access िरना चाहते है Age िे द्वारा इसे access िर सिते है।
  • 30. 24 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m Scope of variables िोई variable program में िाँ हा ति िाम िर सिता है। ये उसिा scope होता है। Scope िे according variables िो 2 categories में divide किया गया है। Local variables Local variables वो variables होते है जो program िे किसी छोटे block में define किये जाते है जैसे िी function या control statement blocks या िोई और block ({ }) भी हो सिता है। इस तरह िे variables िा यूज़ ससर्फ इस block ति ही limited रहता है। जैसे िी यदद आपने किसी function में िोई variable create किया है तो आप उस variable िो उस function िे बाहर access नहीीं िर सिते है। उदाहरर् िे सलए ननचे ददए गए program िो देखखये। #include <stdio.h> void myFunction(); int main() { int num=6; myFunction(); printf("Num in main() : %d", num); return 0; } void myFunction() { int num= 5; printf("Num in myFunction : %dn",num); } ऊपर ददया गया program ननचे ददया गया output generate िरता है। Num in myFuntion() : 5 Num in main() : 6
  • 31. 25 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m Global variables Global variables वो variables होते है जजनिा scope पुरे program में होता है। इन variables िो आप पुरे program में िीं ही भी access िर सिते है। इसिा उदाहरर् ननचे ददया जा रहा है। #include <stdio.h> int num=5; void myFunction(); int main() { myFunction(); printf("Num in main() : %d",num); return 0; } void myFunction() { printf("Num in myFunction : %dn",num); } ऊपर ददया गया program ननचे ददया गया output generate िरता है। Num in myFunction() : 5 Num in main() : 5 Constants in C Constants वो variables होते है जजनिी value change नहीीं होती है। जब भी आप िोई constant declare िरते है तो program िे execution िे दौरान उसिी value fixed रहती है। यदद इसिी value change िरने िी िोसशश िी जाती है तो program में error आ जाती है। इन्हें literals भी िहा जाता है। Constants िो आप 2 तरह से declare िर सिते है।  Using #define  Using Const keyword
  • 32. 26 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m Using #define #define एि pre-processor है इसे यूज़ िरिे आप constant declare िर सिते है। इसिा उदाहरर् ननचे ददया जा रहा है। # include <stdio.h> #define result 10 int main() { int a=5, b=6; result = a + b; /* WRONG, (ERROR) Value of constant result variable can not be changed. */ printf("%d", result); return 0; } ऊपर ददया गया program ननचे ददया गया output generate िरता है। error : lvalue required as left operand of assignment result = a + b; ^ Using const keyword Const keyword िे द्वारा भी आप constants declare िर सिते है। इसिा उदाहरर् ननचे ददया जा रहा है। #include <stdio.h> int main() { const int a=5; const int b=6; int c; c = a+b;
  • 33. 27 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m printf("Result is : %d",a); return 0; } ऊपर ददया गया program ननचे ददया गया output generate िरता है। Result is : 11
  • 34. 28 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m C Flow Charts  Introduction to flow chart in Hindi  Symbols of flow chart in Hindi  Examples of flow chart in Hindi Introduction to Flow Chart Flow chart किसी process िा graphical representation होता है। C language िे सन्दभफ में यह program िे execution flow िा graphical presentation होता है। प्रायः जब भी आप िोई program सलखते है तो बबना किसी flow chart िे सलखते है। किसी दूसरे व्यजक्त द्वारा इसे समझना असींभव होता है। Flow chart िे माध्यम से आप अपने program िो graphically represent िरते है। ऐसा िरने से िोई भी आपिे program िे logic िो आपिे बबना भी समझ सिता है। जब आप किसी company िे सलए programmer िे रूप में िाम िरते है तो coding से पहले flow chart बनाना अननवायफ होता है। ऐसा इससलए किया जाता है क्योंकि companies में अक्सर programmers बदलते रहते है। आपिे द्वारा बनाये गए किसी project िो िोई दूसरा व्यजक्त आसानी से समझ सिे और उस पर िाम िर सिे इससलए आपिो flow charts create िरना अननवायफ होता है। Flow chart create िरने िा एि महत्वपूर्फ िारर् ये है िी इससे आपिो program िी गहरी समझ प्राप्त होती है। आप coding से पहले ही उसमे आने वाली errors और result िो देख पाते है। यदद flow chart completly prepare िर सलया गया है तो coding ससर्फ एि simple process रह जाती है जजसमे programmer िो flow chart िे अनुसार code सलखना होता है। Flow chart िी सबसे बडी ववशेषता ये होती है िी flow chart किसी ववशेष programming language िे सलए नहीीं होता है। Flow chart िो देखिर आप किसी भी programming language में process िो implement िर सिते है। बडी companies project develop िरने से पहले flow chart पर बहुत सा समय लगाती है। Flow chart आपिे program िा blue print होता है। ये मिान बनाने से पहले उसिा नक्शा बनाने जैसा होता है। जजतना समय coding में लगता है उससे िई अधधि समय flow chart में लगाया जाता है। Algorithms भी flow chart िे अनुसार ही बनायीीं जाती है। हर अच्छे programmer िो इसे सीखना चादहए क्योंकि यह एि बहुत ही powerful tool है। आज िल बहुत से modern text editors जैसे िी Microsoft word आदद flow
  • 35. 29 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m chart create िरने िे सलए built in options provide िरते है। आप इन्हें यूज़ िरिे भी flow charts create िर सिते है। Symbols of Flow Chart किसी program िो graphically समझाने िे सलए िु छ symbols िा प्रयोग किया जाता है। ये symbols आपिो पहले से provide किये गए है। इन्हें flow chart symbols िहा जाता है। हर symbol िा एि मतलब होता है जजससे flow chart देखने वाला आसानी से उसे समझ सिता है। ननचे आपिो table िे माध्यम से flow chart symbols िे बारे में बताया जा रहा है। Name Symbol Explanation Begin/End ये oval symbol होता है। इसे terminal symbol भी िहा जाता है। इसे flow chart िो start और end िरने िे सलए यूज़ किया जाता है। किसी भी processing से पहले program िा start और end point define िरना अत्यींत आवकयि है। Processing जब भी आप िोई execution िरते है या कर्र िोई ऐसा statement जजसमे processing हो रही है उसे processing symbol से दशाफया जाता है। Input/Output Program िे input और output िो दशाफने िे सलए आप parallelogram िा इस्तेमाल िरते है। Decision Program िे decision making statements िो दशाफने िे सलए diamond symbol यूज़ किया जाता है। Arrow (Flow) Program िा flow ददखाने िे सलए arrow symbol यूज़ किया जाता है। इसे हर symbol िे बाद flow ददखाने िे सलए यूज़ किया जाता है।
  • 36. 30 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m Example of Flow Chart मान लीजजये आप एि addition िा program बनाना चाहते है जो user से 2 numbers read िरता है और उन्हें add िरिे result display िरता है।इसिे सलए आप flow chart इस प्रिार बनाएींगे। ऊपर ददए गए flow chart में सबसे पहले oval symbol से flow chart िो start किया गया है। इसिे बाद rectangle symbol िे द्वारा 3 variables (num1, num2 और Result) declare किये गए है। इसिे बाद parallelogram द्वारा num1 और num2 िो read िरने िी process िो दशाफया गया है। इसिे बाद वापस rectangle symbol िे द्वारा दोनों numbers िे addition और Result variable िो assign िरने िी process िो दशाफया गया है। इसिे बाद parallelogram द्वारा result िो display िरने िी process िो दशाफया गया है। सबसे आखखर में terminal symbol द्वारा flowchart िो stop किया गया है। इस flow chart िो देखिर िोई भी व्यजक्त आसानी से addition िे program िो किसी भी language में बना सिता है। आइये flow chart िा एि और उदाहरर् देखते है। मान लीजजये आप एि program बनाना चाहते है जो दो integer numbers िो read िरता है और जो उनमें से greater हो उसे display िरवाता है। इसिे सलए flow chart इस प्रिार create किया जायेगा।
  • 37. 31 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m ऊपर ददए flow chart में सब िु छ पहले िी तरह ही है बस diamond symbol िे द्वारा condition िे according दोनों numbers में से जो number greater है उसे display किया जा रहा है।
  • 38. 32 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m First C program  C program development life cycle in Hindi  Structure of a C program  Your First C program explained in Hindi C program development life cycle C में िोई भी program create िरने िे 4 steps हो सिते है। ये steps एि particular order में होते है और इनिा अपना िु छ महत्व होता है। आइये पहला C program create िरने से पहले इस process िो समझने िा प्रयास िरते है। 1. सबसे पहले आप एि program िो सलखते है। इसे program development life cycle िा editing part भी िहते है। ये program human readable format में होता है। 2. इसिे बाद आप program िो compile िरते हैं। ये development life cycle िा second step होता है। इस part में सभी bugs िो remove िरिे program िो binary format में convert किया जाता है ताकि computer इसे process िर सिे । 3. इसिे बाद linking process आती है। इस process में program िो necessary libraries िे साथ link किया जाता है। जैसे िी आपिो पता है िी C िा basic program भी बबना library िो include किये नहीीं execute हो सिता है। Libraries C program िो execute होने िे सलए environment provide िरती है। 4. इसिे बाद executable file produce िर दी जाती है। जजसे आप जजतनी बार चाहे execute िर सिते है। Editing process िा output .c source file होती है। Compiling process िा input source file होती है और output .obj files
  • 39. 33 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m होती है। Linking process िा input .obj file होती है और output .exe file होती है। Structure of A C program Your first C program #include <stdio.h> int main() { printf("Hello Readers!"); return 0; } ऊपर ददया गया program ननचे ददया output generate िरता है। Hello Readers! सबसे पहली line में <stdio.h> header file िो program में include किया गया है। ये एि standard input/output header file होती है जो program में input और output िो handle िरती है। इन्हें pre processor directives भी िहते है।
  • 40. 34 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m इसिे बाद main() method िो start किया गया है। Main method से ही program िा execution start होता है। इसी method में सभी instructions सलखे जाते है। Main method िा start और end curly brackets िे द्वारा show किया जाता है। इन curly brackets िे भीतर िे सभी instructions execute किये जाते है। Main function िो int type िे साथ define किया गया है। ये एि standard है। Int type िे बारे में आप आगे िी tutorials में जानेंगें। Main function िो एि integer value return िरनी होती है। यदद आप program में main() function से िोई value return नहीीं िरते है तो program िे आखखर में return 0 statement define िरते है। Commenting Comments आपिे program में वो text होता है जजसे compiler ignore िर देता है। ये text बािी statements िी तरह execute नहीीं होता है। Comments program में किसी statement िो या कर्र program िो define िरने िे सलए यूज़ किये जाते है। C language में commenting िी general form नीचे दी जा रही है। /* your comment text here */ आइये अब comments िे यूज़ िो एि उदाहरर् से समझने िा प्रयास िरते है। /* This is a c program which shows Hello World message on execution */ #include <stdio.h> int main() /* Main function starts from here*/ { printf("Hello World!"); /* This statement will print Hello World message */ return 0; } जैसा िी आप ऊपर ददए गए program में देख सिते है, comments िे माध्यम से program और दूसरे statements िे बारे में explanation दी गयी है। ये program ननचे ददया गया output generate िरता है। Hello World!
  • 41. 35 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m C Operators  Introduction to C operators in Hindi  Types of C operators in Hindi  Arithmetic operators in Hindi  Relational operators in Hindi  Logical operators in Hindi  Bit wise operators in Hindi  Assignment operators in Hindi  Conditional operator in Hindi  Increment/Decrements operators in Hindi  Special C operators in Hindi Introduction to C operators Variables िे अींदर values store िरवािर आप उन variables पर िई प्रिार िे operations perform िर सिते है। उदहारर् िे सलए दो integer variables िे अींदर value store िरवािर आप addition िा operation perform िर सिते है और उन दोनों variables िी values िे sum िो print िरवा सिते है। इसी प्रिार आप और भी अलग अलग operations variables िे साथ perform िर सिते है। Variables िे साथ operations perform िरने िे सलए आपिो अलग अलग operators यूज़ िरने पडते है। इस chapter में आपिो ऐसे ही operators िे बारे में बताया जा रहा है। Operations में operators िे साथ जो variables यूज़ होते है वो operand िहलाते है। उदाहरर् िे सलए नीचे ददए गए statement िो देखखये। c = a + b; उपर ददए गए statement में a और b िो operator (+) िे साथ यूज़ किया गया है इससलए ये दोनों variables operands िहलायेंगे। Operators 2 प्रिार िे होते है।  Unary - इस प्रिार िे operators ससर्फ एि ही operand िे साथ यूज़ किये जाते है।  Binary - इस प्रिार िे operators िे साथ 2 operands यूज़ किये जाते है। आइये अब C language में यूज़ होने वाले अलग अलग operators िे बारे में जानने िा प्रयास िरते है।
  • 42. 36 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m Arithmetic operators Arithmetic operator mathematical operations perform िरने िे सलए यूज़ किये जाते है। जैसे िी addition, subtraction, division और multiplication आदद। Arithmetic operators 5 प्रिार िे होते है। ये basic mathematical operator होते है। Operators Description + (Addition) ये operator दो variables िी values िो add िरता है। - (Subtraction) ये operator एि variable िी value में से दूसरे variable िी value subtract िरता है। * (Multiplication) ये operator 2 variables िी values िो multiply िरता है। / (Division) ये operator एि variable िी value से दूसरे variable िी value िो divide िरता है। % (Modulus) ये operator division िे बाद शेष बची हुई value िो प्राप्त िरने िे सलए यूज़ किया जाता है। Example #include <stdio.h> int main() { int a=10; int b=5; int c; printf(“Value of a is : %dn”,a); printf(“Value of b is : %dn”,b); printf(“n”); c = a + b; /* Addition operator */ printf(“Addition of a + b is : %dn”,c); c = a - b; /* Subtraction operator */ printf(“Subtraction of a - b is :%dn”,c); c = a * b; /* Multiplication operator */ printf(“Multiplication of a * b is : %dn”,c); c = a / b; /* Division operator */ printf(“Division of a / b is : %dn”,c); c = a % b; /* Modulus operator */ printf(“Modulus is of a is : %dn”,c);
  • 43. 37 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m return 0; } ऊपर ददया गया program ननचे ददया output generate िरता है। Value of a is : 10 Value of b is : 5 Addition of a + b is : 15 Subtraction of a – b is : 5 Multiplication of a * b is : 50; Division of a / b is : 2 Modulus of a % b is : 0 Relational operators Relational operators दो variables िी values िो compare िरने िे सलए यूज़ किये जाते है। जैसे िी आप इन operators िा यूज़ िरिे पता लगा सिते है िी क्या किन्ही दो variables िी values बराबर है और यदद बराबर नहीीं है तो िौनसे variable िी value बडी है और िौनसे variable िी value छोटी है। इस तरह िे operators िो conditional statements (if,if-else,switch,for,while आदद) िे साथ यूज़ किया जाता है। ये operators condition check िरने िे सलए यूज़ किये जाते है। Condition true होने पर value true हो जाती है और condition false होने पर value false हो जाती है। C language में यूज़ होने वाले सभी relational operators िे बारे में नीचे ददया जा रहा है। Operators Descriptions == (Equal To) ये operator check िरता है िी क्या दोनों variables िी values equal है। != (Not Equal To) ये operator check िरता है िी क्या दोनों variables िी values non equal है। < (Lesser Than) ये operator check िरता है िी क्या left operand िी value right operand से छोटी है। > (Greater Than) ये operator check िरता है िी क्या left operand िी value right operand से बडी है। <= (Lesser than equal) ये operator check िरता है िी क्या left operand िी value right operand से छोटी या उसिे समान है। >= (Greater ये operator check िरता है िी क्या left operand िी value
  • 44. 38 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m than equal) right operand से बडी या उसिे समान है। Example #include <stdio.h> int main() { int a = 10; int b = 5; int c; printf("Value of a is : %dn", 10); printf("Value of b is : %dn",5); printf("Are a & b equal ? : "); /* Equals to operator */ if(a == b) { printf("TRUEn"); } else { printf("FALSEn"); } printf("Are a & b are not equal ? :"); /* Not equals to operator */ if(a!=b) { printf("TRUEn"); } else { printf("FALSEn"); } printf("Is a less than b ? :"); /* Less than operator */ if(a < b) { printf("TRUE n"); } else { printf("FALSE n"); } printf("Is a greater than b ? : "); /*Greater than operator */ if(a > b) { printf("TRUEn"); } else {
  • 45. 39 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m printf("FALSEn"); } printf("Is a less than equal to b ? :"); /* Less than equal operator */ if(a <= b) { printf("TRUEn"); } else { printf("FALSEn"); } printf("Is a greater than equal to b ?"); /*Greater than equal operator */ if(a >= b) { printf("TRUE"); } else { printf("FALSE"); } return 0; } ऊपर ददया गया program ननचे ददया output generate िरता है। Value of a is : 10 Value of b is : 5 Are a & b equal ? : FALSE Are a & b are not equal ? :TRUE Is a less than b ? :FALSE Is a greater than b ? : TRUE Is a less than equal to b ? :FALSE Is a greater than equal to b ?TRUE Logical operators Logical operators िो decision making statements िे साथ यूज़ किया जाता है। ये operators control statements में एि साथ दो condition िो check िरने िे सलए यूज़ किये जाते है। उदाहरर् िे सलए आप किसी if statement में एि िी जगह 2 conditions check िर सिते है। Logical operators िे बारे में नीचे ददया जा रहा है। Operators Description && (AND) जब दोनों conditions true होती है तब control statement िी
  • 46. 40 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m value true हो जाती है। || (OR) जब िोई भी एि condition true हो तो भी control statement िी value true हो जाती है। ! (NOT) ये operator एि ही condition िे साथ यूज़ किया जाता है। जब वो condition false होती है तो control statement िी value true हो जाती है। Example #include <stdio.h> int main() { int a = 4; int b = 10; printf("Value of a is :%dn",a); printf("Value of b is :%dn",b); printf("Are both a & b greater than 5? :"); /* && AND operator */ if( a >5 && b >5) { printf("TRUEn"); } else { printf("FALSEn"); } printf("Is either a or b greater than 5? : "); /* || OR operator */ if( a > 5 || b > 5) { printf("TRUEn"); } else { printf("FALSEn"); } printf("Is a not equal to b?"); /* ! NOT operator */ if(!(a==b)) { printf("TRUE"); } else { printf("FALSE"); }
  • 47. 41 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m return 0; } ऊपर ददया गया program ननचे ददया output generate िरता है। Value of a is :4 Value of b is :10 Are both a & b greater than 5? :FALSE Is either a or b greater than 5? : TRUE Is a not equal to b?TRUE Bit wise operators Bit wise operators ददए गए variables पर bit level operations perform िरने िे सलए यूज़ किये जाते है। Variables िी decimal values bits में convert िी जाती है। इसिे बाद उन bits पर operations perform किये जाते है। C language में यूज़ होने वाले bit wise operators िे बारे में नीचे ददया जा रहा है। Operators Description & (Bit wise AND) इस operator िे द्वारा दोनों variables िी same position वाली bits िे साथ AND operation perform किया जाता है। | (Bit wise OR) इस operator िे द्वारा दोनों variables िी same position वाली bits िे साथ OR operation perform किया जाता है। ~ (Bit wise NOT) ये operator ससर्फ एि ही operand िे साथ यूज़ किया जाता है। जजस variable िे साथ इसे यूज़ किया जाता है उस variable िी value िी सभी bits opposite हो जाती है। जैसे िी 0 है तो 1 हो जाती है और 1 है तो zero हो जाती है। ^ (XOR) ये एि special type िा OR operator होता है। ये operator opposite bits होने पर 1 return िरता है और same bits होने पर 0 return िरता है। << (Left Shift) ये operator left side िे variable िी bits िो right side िे variable में दी
  • 48. 42 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m गयी value जजतना left में shift िरता है। >> (Right Shift) ये operator left side िे variables िी bits िो right side िे variable में दी गयी value जजतना right में shift िरता है। जैसा िी आपिो पता है bit wise operators bits िे साथ work िरते है। मान लीजजये आपने program में 2 variables a और b create किये हुए है। इन दोनों variables में आपने क्रमशः 3 और 5 values store िरवाई हुई है। इनिी bits पर work िरने िे सलए सबसे पहले आप इन्हें binary में convert िर सिते है। 3 = 00000011 5 = 00000101 ससर्फ आपिो समझाने िे purpose से इन्हें binary में convert किया गया है। आपिो program में binary values insert िरवाने िी आवकयिता नहीीं है। Computer information िो binary form में ही store िरता है। ऊपर define किये गए सभी operations इन bits पर ही perform किये जायेंगे। Example #include <stdio.h> int main() { int a = 3; int b = 5; int c; c = a & b; printf("Result of a & b is : %dn",c); c= a|b; printf("Result of a|b is : %dn",c); c = ~a; printf("Result of ~a : %dn",c); c = a ^ b; printf("Result of a ^ b is : %dn",c); c= a<<4; printf("Result of shifting a left by 4 places is : %dn",c); c=a>>4; printf("Result of shifting a right by 4 places is :%dn",c); return 0;
  • 49. 43 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m } ऊपर ददया गया program ननचे ददया output generate िरता है। Result of a & b is : 1 Result of a|b is : 7 Result of ~a : -4 Result of a ^ b is : 6 Result of shifting a left by 4 places is : 48 Result of shifting a right by 4 places is :0 Assignment operators Assignment operator variables िी values िो एि दूसरे िो assign िरने िे सलए यूज़ किये जाते है। C language में यूज़ होने वाले ववसभन्न assignment operators िे बारे में नीचे ददया जा रहा है। Operators Description = ये operator right side िे operand िी value िो left side िे operand िो assign िरता है। += ये operator left side िे operand में right side िे operand िी value िो add िरिे result left side वाले operand िो assign िरता है। इसे आप इस प्रिार भी सलख सिते है। a = a+b; -= ये operator left side िे operand िी value में से right side िे operand िी value िो subtract िरिे result left side िे variable में store िरवाता है। इसे आप इस प्रिार भी सलख सिते है। a=a-b; *= ये operator left side िे operand िी value िो right side िे operand िी value से multiply िरिे result िो left side िे operand में store िरता है। /= ये operator left operand िी value िो right operand िी value से divide िरिे result िो left side िे operand में store िरता है। %= ये operator left side िे operand िी value िो right side िे operand िी value से divide िरिे शेष बचे हुए result िो left side िे operand में store िरता है।
  • 50. 44 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m Example #include <stdio.h> int main() { int a; int b = 5; a = b; printf("Result of a = b is : %d",a); a+=b; printf("Result of a+=b is : %d ",a); a-=b; printf("Result of a-=b is : %dn",a); a*=b; printf("Result of a*=b is : %d",a); a/=b; printf("Result of a/=b is : %d",a); a%=b; printf("Result of a%=b is: %d",a); return 0; } ऊपर ददया गया program ननचे ददया output generate िरता है। Result of a = b is : 5 Result of a+=b is : 10 Result of a-=b is : 5 Result of a*=b is : 25 Result of a/=b is : 5 Result of a%=b is: 0 Increment/Decrements operators किसी भी variable िी value िो एि number से instantly increase या decrease िरने िे सलए आप increment/ decrements operators यूज़ िर सिते है। इनिे बारे में नीचे ददया जा रहा है। Operators Description ++ (increment) ये एि unary operator होता है। ये operand िी value िो
  • 51. 45 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m एि number से increase िरता है। जब यह operand िे पहले लगता है तो value पहले increment होती है और बाद में यूज़ िी जाती है। जब ये operator operand िे बाद लगता है तो operand िी value यूज़ होने िे बाद increment होती है। --(decrements) ये भी एि unary operator होता है। ये operand िी value िो एि number से decrease िरता है। जब इसे operand से पहले यूज़ किया जाता है तो value यूज़ होने से पहले decrease होती है। जब इसे variable िे बाद यूज़ किया जाता है तो value पहले यूज़ होती है और बाद में decrease होती है। Conditional (?:) operator Conditional operator िो ternary operator भी िहा जाता है। ये if-else statement िी short form होती है। इसिा general structure इस प्रिार होता है। contion ? stmnt1 : stmnt 2; यदद condition true हो तो statement one return होगा नही तो statement 2 return होगा। इसिा उदाहरर् ननचे ददया जा रहा है। 5>3 ? true : false; Special C operators Operators Description sizeof (var_name ) ये operator memory में variables िी size return िरता है। & ये operator variables िा memory address return िरता है। * ये operator variable िा pointer return िरता है।
  • 52. 46 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m C Decision Making  Introduction to C decision making in Hindi  C If statement in Hindi  C If else statement in Hindi  C switch statement in Hindi Introduction to C decision making आप अपने program में िौनसे statements िो execute िरना चाहते है और िौनसे statements िो skip िरना चाहते है ये आप खुद decide िर सिते है। इसे decision making िहते है। ज्यादातर decision making किसी condition िे base पर िी जाती है। एि particular condition आने पर आप मनचाहे statements िो execute िर सिते है। इसिे सलए आप िु छ built in statements िो यूज़ िरते है। क्योंकि ये statements conditions िे साथ िाम िरते है इससलए इन्हें conditional statement भी िहा जाता है। और क्योंकि ये statement program में execution िो control िरते है इससलए इन्हें control statements भी िहा जाता है। इन statements िे बारे में जानने से पहले आइये decision making िो एि उदाहरर् से समझने िा प्रयास िरते है। मान लीजजये आप किन्हीीं दो students में से जजसिी age अधधि हो उसिा नाम print िरना चाहते है। आप ऐसा किस प्रिार िर सिते है? नीचे ददए हुए program िो देखखये। #include <stdio.h> #include <conio.h> void main() { raviAge = 40; ankitAge = 32; } उपर ददए गए उदाहरर् में 2 students िी age 2 variables में store िी गयी है। लेकिन आपिो ससर्फ उसी student िी age print िरनी है जजसिी age सबसे ज्यादा हो। इस situation में आपिो decision लेने िी आवकयिता है। ऐसा आप किसी भी decision making statement (If, If-else, Switch) िे द्वारा िर सिते है।
  • 53. 47 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m आइये इन statements िे बारे में detail से जानने िा प्रयास िरते है। If statement If statement िा general syntax ननचे ददया जा रहा है। if(condition) { // statements } If statement curly braces {} िे द्वारा एि block define िरता है। जब condition true होती है तो इस block में ददए गए statement execute होते है। यदद condition false हो तो इस पुरे block िो compiler skip िर देता है। यदद उपर ददए गए example में if statement िा यूज़ किया जाये तो program िो इस प्रिार सलखा जा सिता है। #include <stdio.h> int main() { int raviAge = 40; int ankitAge = 32; if(raviAge > ankitAge) { printf("Ravi is elder."); } return 0; } उपर ददए गए उदाहरर् में conditional operator िा यूज़ िरते हुए एि condition लगायी गयी है। यदद Ravi िी age Ankit से अधधि है तो if statement में ददया गया printf() statement execute होगा है। लेकिन यदद ऐसा नहीीं है तो ये statement execute नहीीं होगा। ये program ननचे ददया गया output generate िरेगा। Ravi is elder.
  • 54. 48 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m If-Else statement If else statement िो if statement िा ही part माना जाता है। लेकिन इसमें else block और add किया जाता है। Else block में ददए गए statement तब execute होते है जब if िी condition false हो जाती है। If-else statement िा general syntax नीचे ददया जा रहा है। if(condition) { //statements } else { //statements } जैसा िी आपिो पता है if िी condition true होने पर if block में ददए गए statements execute होते है। लेकिन आप ये भी decide िर सिते है िी यदद condition false हो तो क्या किया जाना चादहए। इसिे सलए आप else block यूज़ िरते है। ये block हमेशा if block िे बाद में आता है। इस block में वो statements सलखे जाते है जो िी condition false होने पर execute होंगे। यदद ऊपर ददए गए उदाहरर् में if else statement िा प्रयोग किया जाये तो आप उसे इस प्रिार सलख सिते है। #include <stdio.h> void main() { int raviAge = 20; int ankitAge = 32; if(raviAge > ankitAge) { printf("Ravi is elder"); } else { printf("Ankit is elder"); } } ऊपर ददया गया program ननचे ददया गया output generate िरता है। Ankit is elder.
  • 55. 49 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m else if यदद आप if और else िे बीच में एि और condition लगाना चाहते है तो ऐसा आप else if block define िरिे िर सिते है। if(raviAge > ankitAge) { printf("Ravi is elder"); } else if(ankitAge > raviAge) { printf("Ankit is elder"); } else { printf("Both are equal"); } Switch statement Switch statement भी if statement िी तरह ही होता है लेकिन इसमें condition check िरने िी बजाय case check किया जाता है। एि particular case आने पर आप जो statements execute िरना चाहते है उन्हें आप case िे अींदर सलखते है। Case एि integer variable से match किया जाता है। जो case integer variable से match हो जाता है वही case execute हो जाता है Switch statement िा general syntax नीचे ददया जा रहा है। int caseNumber = n; switch(caseNumber) { case 1: //statements to be executed break; case 2: //statements to be executed break; default: //statements to be executed
  • 56. 50 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m break; } जब आप caseNumber variable िो किसी integer value िे साथ set िरते है और इसे switch statement में pass िरते है तो ये number जजस caseNumber से match िरेगा वही case execute होगा। जैसे िी यदद आपने case number में 2 pass किया है तो second number िा case execute होगा और break से पहले िे सभी statements execute हो जायेंगे। यदद िोई case match नहीीं िरता है तो default case execute होता है। यदद हर case िे बाद break statement ना यूज़ किया जाये तो सभी case execute हो जाएींगे। Case िो आप alphabets से भी define िर सिते है। आइये switch statement िो एि उदाहरर् िे माध्यम से समझने िा प्रयास िरते है। #include <stdio.h> void main() { int caseNumber; printf("Enter a number "); scanf("%d",&caseNumber); switch(caseNumber) { case 1: printf("nFirst Case executed...."); break; case 2: printf("nSecond Case executed...."); break; default: printf("nNone of the case matched. You can only enter 1 or 2"); break; } }
  • 57. 51 | P a g e © w w w . b e s t h i n d i t u t o r i a l s . c o m उपर ददए गए उदाहरर् में user से एि number enter िरवाया जा रहा है और उस number िे base पर matching case execute िरवाया जा रहा है। ये program ननचे ददया गया output generate िरता है। Enter a number : 2 Second case executed....