Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 41

PROGRAMMING IN C

SHUBHAM COMPUTECH CSC ACADEMY

0
1
CHAPTER 1- INTRODUCTION
 WHAT IS PROGRAMMING?
 WHAT IS C?
 USES OF C
 BASIC STRUCTURE OF C PROGRAMMING
 COMMENTS
 COMPILATION AND EXECUTION
 LIBRARY FUNCTIONS
 C TOKENS
 IDENTIFIERS
 KEYWORDS
 CONSTANTS
 OPERATORS
 DATA TYPES IN C

2
1. WHAT IS PROGRAMMING – 4. C is used to develop games an area where latency is
Computer Programming is a medium for us to very important. i.e. Computer has to react quickly
communicate with computers. Just like we use ‘Hindi’ on user input.
or ‘English’ to Communicate with each other, 1. प्रोग्रामिंग क्या है –
programming is a way for us to deliver our instructions कं प्यूटर प्रोग्रामिंग हमारे लिए कं प्यूटर के साथ संवाद करने का
to the computer. There is a close analogy between एक माध्यम है। जैसे हम एक-दूसरे के साथ संवाद करने के लिए 'हिंदी' या
learning English language and learning C language.
The classical method of learning English is to first learn
'अंग्रेजी' का उपयोग करते हैं, प्रोग्रामिंग हमारे लिए हमारे निर्देशों को कं प्यूटर
the alphabets used in the language, then learn to को वितरित करने का एक तरीका है। अंग्रेजी भाषा सीखने और C भाषा
combine these alphabets to form words, which in turn सीखने के बीच एक करीबी सादृश्य है। अंग्रेजी सीखने की शास्त्रीय विधि
are combined to form sentences and sentences are पहले भाषा में उपयोग किए जाने वाले वर्णों को सीखना है, फिर शब्दों को
combined to form paragraphs. Learning C is similar बनाने के लिए इन वर्णों को संयोजित करना सीखें, जो बदले में वाक्य बनाने
and easier. Instead of straight-away learning how to के लिए संयुक्त होते हैं और वाक्यों को
write programs, we
must first know what
पैराग्राफ बनाने के लिए जोड़ा जाता है। C
alphabets, numbers and सीखना समान और आसान है। सीधे प्रोग्राम
special symbols are लिखना सीखने के बजाय, हमें पहले यह
used in C, then how जानना चाहिए कि C में किस अक्षर, संख्या
using them constants, और विशेष प्रतीकों का उपयोग किया जाता
variables and है, फिर उनका उपयोग करके स्थिरांक, चर
keywords are
constructed, and finally
और कीवर्ड का निर्माण कै से किया जाता है,
how are these combined और अंत में इन्हें एक निर्देश बनाने के लिए
to form an instruction. A group of instructions would be कै से जोड़ा जाता है। निर्देशों के एक समूह को एक पोग्राम बनाने के लिए
combined to form a program. जोड़ा जाएगा।
2. WHAT IS C – 2. C क्या है –
C is a programming language. It is a one of the oldest C एक प्रोग्रामिंग भाषा है। यह सबसे पुरानी और बेहतरीन प्रोग्रामिंग
and finest programming languages’ was developed by भाषाओं में से एक है जिसे बेल प्रयोगशालाओं (पूर्व में AT & T बेल
Dennis M. Ritchie at Bell Laboratories (formerly
AT&T Bell Laboratories). It was initially designed for प्रयोगशालाओं) में डेनिस एम रिची द्वारा विकसित किया गया था। शुरू में
programming UNIX operating system. The software यह प्रोग्रामिंग यूनिक्स ऑपरेटिंग सिस्टम के लिए डिज़ाइन किया गया था।
tool as well as the C compiler is written in C. Major सॉफ्टवेयर टूल के साथ-साथ C कं पाइलर को C में लिखा गया है। विंडोज,
parts of operating systems like Windows, UNIX, Linux यूनिक्स, लिनक्स जैसे ऑपरेटिंग सिस्टम के प्रमुख हिस्सों को अभी भी C में
is still written in C. This is because even today when it
comes to performance (speed of execution) nothing
लिखा गया है। ऐसा इसलिए है क्योंकि आज भी जब प्रदर्शन (निष्पादन की
beats C. Moreover, if one is to extend the operating गति) की बात आती है तो कु छ भी C को हरा नहीं सकता है। इसके
system to work with new devices one needs to write अलावा, यदि कोई नए उपकरणों के साथ काम करने के लिए ऑपरेटिंग
device driver programs. These programs are सिस्टम का विस्तार करना चाहता है, तो उसे डिवाइस ड्राइवर प्रोग्राम
exclusively written in C.
लिखने की आवश्यकता है। ये कार्यक्रम विशेष रूप से C में लिखे गए हैं।
3. USES OF C –
C language is used to program a wide variety of 3. C भाषा का उपयोग –
systems some of the uses of C are as follows: C विभिन्न प्रकार के सिस्टम को प्रोग्राम करने के लिए किया जाता है C के
1. Major parts of windows, Linux and other operating कु छ उपयोग इस प्रकार हैं:
systems are written in C.
2. C is used to write driver programs for devices like
1. विंडोज, लिनक्स और अन्य ऑपरेटिंग सिस्टम के प्रमुख भागों को C
Tablets, printers etc. में लिखा जाता है।
3. C language is used to program embedded systems 2. C का उपयोग टैबलेट, प्रिंटर आदि जैसे उपकरणों के लिए ड्राइवर
where programs need to run faster in limited प्रोग्राम लिखने के लिए किया जाता है।
memory (Microwave, cameras etc.)

3
3. C भाषा का उपयोग एम्बेडेड सिस्टम को प्रोग्राम करने के लिए किया
जाता है जहां प्रोग्राम को सीमित मेमोरी (माइक्रोवेव, कै मरा आदि) में
तेजी से चलाने की आवश्यकता होती है।
4. C का उपयोग गेम विकसित करने के लिए किया जाता है, एक ऐसा
क्षेत्र जहां विलंबता बहुत महत्वपूर्ण है। यानी कं प्यूटर को उपयोगकर्ता
इनपुट पर जल्दी से प्रतिक्रिया करनी होती है।
4. BASIC STRUCTURE OF C 4. C प्रोग्रामिंग की मूल संरचना
PROGRAMMING

a. Documentation section

b. Link section
c. Definition section
d. Global declaration section
e. main()
{
f. Declaration part
g. Executable part
(statements)
}
h. Sub-program section

 प्रलेखन अनुभाग का उपयोग प्रोग्राम के बारे में किसी भी जानकारी


 The documentation section is used for displaying
any information about the program like the को प्रदर्शित करने के लिए किया जाता है जैसे कि कार्यक्रम का
purpose of the program, name of the author, date उद्देश्य, लेखक का नाम, लिखी गई तारीख और समय आदि, और
and time written etc, and this section should be इस खंड को टिप्पणी लाइनों के भीतर संलग्न किया जाना चाहिए।
enclosed within comment lines. The statements
प्रलेखन अनुभाग में दिए गए कथन को कं पाइलर द्वारा अनदेखा
in the documentation section are ignored by the
compiler. किया जाता है।
 The link section consists of the inclusion of  लिंक अनुभाग में हेडर फ़ाइलों को शामिल करना शामिल है।
header files.
 Anything declared in the global declaration  ग्लोबल डिक्लेरेशन अनुभाग में घोषित कु छ भी पूरे कार्यक्रम में
section is accessible throughout the program, i.e. सुलभ है, यानी कार्यक्रम में सभी कार्यों के लिए सुलभ है।
accessible to all the functions in the program.  main() फ़ं क्शन किसी भी कार्यक्रम के लिए अनिवार्य है और इसमें
 main() function is mandatory for any program
and it includes two parts:
दो भाग शामिल हैं:
 Declaration part  डिक्लेरेशन भाग
 Executable part.
 The last section, i.e. sub-program section is
 निष्पादन योग्य भाग
optional and used when we require including  अंतिम खंड, यानी उप-प्रोग्राम अनुभाग वैकल्पिक है और इसका
user defined functions in the program. उपयोग तब किया जाता है जब हमें प्रोग्राम में उपयोगकर्ता परिभाषित
कार्यों को शामिल करने की आवश्यकता होती है।
Our first C Program/ हमारा पहला C Program – Note:
 #include <stdio.h> includes the standard input output library
functions. The printf() function is defined in stdio.h .
# include<stdio.h>
 #include <conio.h> includes the console input output library
#include<conio.h> functions. The getch() function is defined in conio.h file.
 void main() The main() function is the entry point of every
void main() program in c language. The void keyword specifies that it returns
no value.
{
4
नोट:
clrscr ();
 #include <stdio.h> मानक इनपुट आउटपुट लाइब्रेरी फ़ं क्शन शामिल हैं।
This plain text is compilation of Instructions
in a particular sequence. The compiler performs
some basic checks and finally converts the program
into an executable.

7. LIBRARY FUNCTIONS
Library functions are built-in functions that are
grouped together and placed in a common location
called library. Each function here performs a specific
All C programs have to follow a basic structure. operation. We can use this library functions to get the
There are some rules which are applicable to all the pre-defined output. All C standard library functions
C programs: are declared by using many header files. These library
 Every program’s execution starts from main functions are created at the time of designing the com-
() function. pilers. We include the header files in our C program
 All The Statements are terminated with a by using #include<filename.h>. Whenever the pro-
semicolon. gram is run and executed, the related files are in-
 Instructions are case – sensitive. cluded in the C program.
 Instructions are executed in the some order सभी C प्रोग्रामों को एक बुनियादी संरचना का पालन करना होगा। कु छ
in which they are written.
नियम हैं जो सभी C प्रोग्रामों पर लागू होते हैं:
5. COMMENTS  प्रत्येक प्रोग्राम का निष्पादन मुख्य () फ़ं क्शन से शुरू होता है।
Comments are used to clarify something about the  सभी कथन को (;) अर्धविराम के साथ समाप्त किया जाता
program in plain language. It is a way for us to add है।
notes to our program. There are two types of
comments in C.  निर्देश मामले हैं - संवेदनशील।
1. Single line comment: - // this is a com-  निर्देशों को कु छ क्रम में निष्पादित किया जाता है जिसमें वे
ment.
2. Multi – line comment :- /* This is a multi- लिखे जाते हैं।
line comment */ 5. टिप्पणियाँ
Comment in a C program are not executed and
are ignored. टिप्पणियों का उपयोग सादे भाषा में कार्यक्रम के बारे में कु छ स्पष्ट करने के
लिए किया जाता है। यह हमारे लिए हमारे कार्यक्रम में नोट्स जोड़ने का एक
6. COMPILATION AND EXECUTION तरीका है। सी में दो प्रकार की टिप्पणियां हैं।
A compiler is a 1. एकल पंक्ति टिप्पणी: - / / यह एक टिप्पणी है।
First.C C Compiler Execution
computer program which 2. बहु-पंक्ति टिप्पणी: - / * यह एक बहु-पंक्ति
converts a C program into machine language so that
it can be easily understood by the computer. A C
टिप्पणी है */
program is written in plain text. C प्रोग्राम में टिप्पणी निष्पादित नहीं की जाती है और उन्हें अनदेखा
किया जाता है।
Library के लिए उपयोग करें
Func- Heade के लिए उपयोग करें
tion r File Use for 6. संकलन और निष्पादन
printf() stdio.h printing desired स्क्रीन पर वांछित कं पाइलर एक कं प्यूटर प्रोग्राम होता है जो सी प्रोग्राम को मशीन भाषा
output on the आउटपुट मुद्रित करना में परिवर्तित First.exe करता है ताकि वह कं प्यूटर द्वारा
screen
scanf() stdio.h accepting dataउपयोगकर्ता से डेटा आसानी से समझा जा सके एक सी प्रोग्राम सादे
from the userस्वीकार करना टेक्स्ट में लिखा गया है। यह प्लेन टेक्स्ट एक विशेष अनुक्रम में
strcmp string.h comparing two दो स्ट्रिंग्स की तुलना निर्देशों का संकलन है। कं पाइलर कु छ बुनियादी जांच करता है और
strings
length() string.h finding out the लंबाई का पता लगाएं अंत में प्रोग्राम को निष्पादन योग्य में परिवर्तित करता है।
length of string
pow() math.h for calculating प्रतिपादक की गणना 7. लाइब्रेरी फ़ं क्शन
the exponent के लिए
5
sqrt() math.h for calculating वर्ग मूल की गणना के
the square root लिए
लाइब्रेरी फ़ं क्शन अंतर्निहित फ़ं क्शन होते हैं जिन्हें एक साथ समूहीकृ त
किया जाता है और लाइब्रेरी नामक एक सामान्य स्थान पर रखा जाता है।
यहां प्रत्येक फ़ं क्शन एक विशिष्ट ऑपरेशन करता है। हम पूर्व-परिभाषित
आउटपुट प्राप्त करने के लिए इस लाइब्रेरी फ़ं क्शन का उपयोग कर सकते
हैं। सभी C मानक लाइब्रेरी फ़ं क्शन कई हेडर फ़ाइलों का उपयोग करके
घोषित किए जाते हैं। ये लाइब्रेरी फ़ं क्शन कं पाइलर्स को डिजाइन करने के
समय बनाए जाते हैं। हम #include<filename.h> का उपयोग करके
अपने C प्रोग्राम में हेडर फ़ाइलों को शामिल करते हैं। जब भी प्रोग्राम
चलाया और निष्पादित किया जाता है, तो संबंधित फाइलें सी प्रोग्राम में
शामिल होती हैं।

6
8. C TOKENS 3. Variable names are case sensitive.
The smallest individual units are known as tokens. 4. A variable name contains maximum of 30
C has six types of tokens. characters/ Variable name must be upto 8
1: Identifiers characters.
2: Keywords 8. C टोकन
3: Constants सबसे छोटी व्यक्तिगत इकाइयों को टोकन के रूप में जाना जाता है। C में
4: Strings छह प्रकार के टोकन हैं।
5: Special Symbols
1: Identifiers
6: Operators
2: Keywords
A. Identifiers: 3: Constants
Identifiers refer to the names of variables, 4: Strings
constants, functions and arrays. These user-defined 5: Special Symbols
names are called Identifiers. 6: Operators

Rules for naming an Identifier


A. Identifiers:
Identifiers चर, स्थिरांक, फ़ं क्शन और सरणी के नामों को संदर्भित करते हैं।
1. An Identifier can only have alphanumeric
characters (a-z, A-Z, 0-9) and underscore
इन उपयोगकर्ता-परिभाषित नामों को identifiers कहा जाता है।
(_).
2. The first character of an identifier can only एक identifiers के नामकरण के नियम
contain alphabet (a-z, A-Z) or underscore 1. एक identifiers में के वल अल्फ़ान्यूमेरिक वर्ण (a-z, A-Z, 0-9)
(_). और रेखांकन (_) हो सकते हैं।
3. Identifiers are also case sensitive in C. For
2. एक identifiers के पहले वर्ण में के वल वर्णमाला (ए-जेड, ए-जेड)
example name and Name are two different
identifier in C. या अंडरस्कोर (_) हो सकती है।
4. Keywords are not allowed to be used as 3. C में identifiers के स सेंसिटिव होते हैं। उदाहरण के लिए C में
Identifiers. name और Name दो अलग-अलग identifiers हैं।
5. No special characters, such as semicolon,
period, whitespaces, slash or comma are
4. Keywords को identifiers के रूप में उपयोग करने की अनुमति
permitted to be used in or as Identifier. नहीं है।
6. C compiler recognizes only the first 31 5. कोई विशेष वर्ण, जैसे अर्धविराम, अवधि, श्वेत स्थान, स्लैश या
characters of an identifiers. अल्पविराम को identifiers में या उसके रूप में
Ex : Valid Invalid उपयोग करने की अनुमति नहीं है।
STDNAME Return
6. C कं पाइलर एक identifier के के वल
SUB $stay
TOT_MARKS पहले 31 वर्णों को पहचानता है।
1RECORD
_TEMP STD
Variables:
A Variable is an entity whose value can be चर :
changed. A Variable is a container which stores a एक चर एक इकाई है जिसका मूल्य बदला जा सकता है। एक
‘value’. In Kitchen, we have containers storing
Rice, Dal, and Sugar etc. Similar to that variables in चर एक कं टेनर है जो एक 'मूल्य' संग्रहीत करता है रसोई में, हमारे पास
C stores values of a constant. चावल, दाल और चीनी आदि का भंडारण करने वाले कं टेनर हैं। सी में
Example: - a=3; //a is assigned “3”
चर के समान एक स्थिरांक के मूल्यों को संग्रहीत करता है।
b=4.7; //b is assigned “4.7”
c= ‘A’; //c is assigned “A” उदाहरण:- a=3; //a को सौंपा गया है “3”
b=4.7; //b को सौंपा गया है “4.7”
Rule for naming variables in C –
1. First character must be an alphabet or c= ‘A’; //c को सौंपा गया है “A”
underscore (_).
C में चर क s नाम देने का नियम –
2. No special symbol (like comma,
blankspace) other than underscore (_)
1. पहला वर्ण एक वर्णमाला या रेखांकन होना चाहिए (_)
allowed.
7
2. अंडरस्कोर (_) के अलावा किसी विशेष प्रतीक (जैसे ators are of two types based on the number of
अल्पविराम, रिक्त स्थान) की अनुमति नहीं है। operands they work. These are as follows:
3. चर नाम के मामले के प्रति संवेदनशील होते हैं। 1. Binary Arithmetic Operators
The C binary arithmetic operators operate or
4. एक चर नाम में अधिकतम 30 वर्ण होते हैं / चर नाम 8 वर्णों work on two operands. C provides 5 Binary
तक होना चाहिए। Arithmetic Operators for performing arith-
We must create meaningful variable names in our metic functions which are as follows:
programs. This enhances readability of our हमें प्रोगरामों में सार्थक चर नाम बनाने चाहिए। यह हमारे प्रोग्रामों की
programs. पठनीयता को बढ़ाता है।
B. Constants: B. स्थिरांक:
An entity whose value doesn’t change is called as a
एक इकाई जिसका मूल्य नहीं बदलता है उसे स्थिरांक कहा जाता है।
constant.
Types of Constants –
स्थिरांक के प्रकार –
Primarily, there are three types of constants: मुख्य रूप से, स्थिरांक तीन प्रकार के होते हैं:
1. Integer Constant => -1,6,7,9 1. पूर्णांक स्थिरांक = > -1,6,7,9
2. Real Constant => -322.1, 2.5, 7.0 2. वास्तविक स्थिरांक => -322.1, 2.5, 7.0
3. Character Constant =>‘a’ , ‘$’ , ‘e’(Must be 3. वर्ण स्थिरांक = >'a', '$', 'e' (एकल उल्टे अल्पविराम के
enclosed within single inverted commas) भीतर संलग्न होना चाहिए)

C. Keywords: C. कीवर्ड:
These are reserved words, whose meaning is ये आरक्षित शब्द हैं, जिनका अर्थ पहले से ही कं पाइलर को पता है। C
already known to the compiler. There are 32 में 32 कीवर्ड उपलब्ध हैं।
keywords available in C.
auto double int struct do goto sizeof unsigned
creak long else switch static volatile void float
case return enum typedef if continue for short
char register extern union while signed default const

D. ऑपरेटर्स:
D. Operators:
सी ऑपरेटर में प्रतीक होते हैं जिनका उपयोग गणितीय या तार्कि क
In C operators are symbols that are used to perform
mathematical or logical manipulations. The C pro- जोड़तोड़ करने के लिए किया जाता है। सी प्रोग्रामिंग भाषा अंतर्निहित
gramming language is rich with built-in operators. ऑपरेटरों के साथ समृद्ध है। ऑपरेटर डेटा और चर में हेरफे र करने के लिए
Operators take part in a program for manipulating एक कार्यक्रम में भाग लेते हैं और गणितीय या तार्कि क अभिव्यक्तियों का
data and variables and form a part of the mathemat-
ical or logical expressions. C offers various types of
एक हिस्सा बनाते हैं। सी विभिन्न प्रकार के ऑपरेटरों की पेशकश करता है
operators having different functioning capabilities. जिनके पास विभिन्न कार्य क्षमताएं होती हैं।
 अंकगणितीय ऑपरेटर
 Arithmetic Operators
 रिलेशनल ऑपरेटर्स
 Relational Operators
 Logical Operators  लॉजिकल ऑपरेटर्स
 Assignment Operators  असाइनमेंट ऑपरेटर्स
 Conditional Operator
 सशर्त ऑपरेटर
 Bitwise Operators
 Special Operators  बिटवाइज ऑपरेटर्स
 स्पेशल ऑपरेटर्स
Arithmetic Operators are used to perform अरिथमैटिक ऑपरेटर्स का उपयोग दिए गए ऑपरेंड पर गणितीय
mathematical operations such as addition, sub-
traction, multiplication, division, modulus, etc., संचालन जैसे जोड़, घटाव, गुणा, विभाजन, मापांक आदि करने के लिए
on the given operands. The C Arithmetic Oper- किया जाता है। सी अंकगणितीय ऑपरेटर दो प्रकार के होते हैं जो उनके

8
द्वारा काम किए जाने वाले ऑपरेंड की संख्या के आधार पर होते हैं। ये ii. --x: Pre decrement, first decrements and then
निम्नानुसार हैं: do the operation.
iii. x++: Post increment, first do the operation
1. बाइनरी अंकगणितीय ऑपरेटर
and then increment.
C में बाइनरी अंकगणितीय ऑपरेटर दो ऑपरेंड पर काम करते हैं या iv. x- - : Post decrement, first do the operation
काम करते हैं। सी अंकगणितीय कार्यों को करने के लिए 5 and then decrement.
द्विआधारी अंकगणितीय ऑपरेटर प्रदान करता है जो निम्नानुसार हैं:

Oper Name of the Arithmetic Operation अंकगणितीय संक्रिया Syntax


ator Operator
+ Addition Add two operands. दो ऑपरेंड जोड़ें। x+y
– Subtraction Subtract the second operand from the पहले ऑपरेंड से दूसरे ऑपरेंड को घटाएं। x–y
first operand.
* Multiplication Multiply two operands. दो ऑपरेंड को गुणा करें। x*y
/ Division Divide the first operand by the second पहले ऑपरेंड को दूसरे ऑपरेंड से विभाजित करें। x/y
operand.
% Modulus Calculate the remainder when the first शेष की गणना करें जब पहले ऑपरेंड को दूसरे x%y
operand is divided by the second
Operator Symboloperand. Operation
ऑपरेंड परिचालन
से विभाजित किया जाता है। Implementation
Decrement -- Decreases the integer value of चर के पूर्णांक मान को एक से कम --h or h--
Operator the variable by one. करता है।
Increment ++ Increases the integer value of चर के पूर्णांक मान को एक से बढ़ाता ++h or h++
Operator the variable by one. है।
Unary Plus + Returns the value of its अपने ऑपरेंड के मूल्य को लौटाता है। +h
Operator operand.
Unary Minus – Returns the negative of the अपने ऑपरेंड के मूल्य का -h
Operator value of its operand. नकारात्मक लौटाता है।

2. Unary Arithmetic Operators 3. युनरी अंकगणितीय ऑपरेटर


The unary arithmetic operators operate or work युनरी अंकगणितीय ऑपरेटर एक ही ऑपरेंड के साथ काम या
with a single operand. In C, we have two unary काम करते हैं। सी में, हमारे पास दो युनरी अंकगणितीय
arithmetic operators which are as follows:
ऑपरेटर हैं जो निम्नानुसार हैं:
Increment Operator in C
The ‘++’ operator is used to increment the value C में इन्क्रीमेंट ऑपरेटर:
of an integer. It can be used in two ways: '++' ऑपरेटर का उपयोग पूर्णांक के मूल्य को बढ़ाने के लिए किया
1. Pre-Increment जाता है। इसका उपयोग दो तरीकों से किया जा सकता है:
a = ++x; 1. प्री-इंक्रीमेंट a = ++x;
2. Post Increment
a = x++;
2. पोस्ट इंक्रीमेंट a= x++;
Decrement Operator in C
C में डिक्रीमेंट ऑपरेटर :
The ‘--’ operator is used to decrement the value of
an integer. Just like the increment operator, the '--' ऑपरेटर का उपयोग पूर्णांक के मूल्य को कम करने के लिए किया
decrement operator can also be used in two ways: जाता है। इन्क्रीमेंट ऑपरेटर की तरह, डिक्रीमेंट ऑपरेटर का उपयोग भी
1. Pre-Decrement दो तरीकों से किया जा सकता है:
a=--x 1. प्री- डिक्रीमेंट a = --x;
2. Post Decrement
2. पोस्ट डिक्रीमेंट a= x--;
a= x – –.
Note: नोट:
i. ++x: Pre increment, first increment and then i. ++x: प्री-इंक्रीमेंट, पहले इंक्रीमेंट और फिर ऑपरेशन करता
do the operation. है।

9
ii. --x: प्री- डिक्रीमेंट, पहले डिक्रीमेंट और फिर ऑपरेशन करता
है।
iii. x++: पोस्ट इंक्रीमेंट में पहले ऑपरेशन होता है और बाद में
इन्क्रीमेंट होता है।
iv. x- - : पोस्ट डिक्रीमेंट में पहले ऑपरेशन होता है और बाद में
डिक्रीमेंट होता Operator Meaning Example Return value Logical Not: This
है। < is less than 2<9 1 operator reverses
<= is less than or 2<=2 1 the value of the
Relational Op- equal to expression it
erator checks the > is greater than 2>9 0 operates on i.e, it
relationship > = is greater than 3>=2 1
makes a true
between two oper- or equal to
expression false
ands. If the relation = = is equal to 2==3 0
and false
is true, it returns 1; != is not equal to 2!=2 0
expression true.
if the relation is false, it returns value 0. Operands
may be variables, constants or expressions.
Relational operators are used in decision mak- Op !Op
ing and loops. True False
False True

रिलेशनल ऑपरेटर दो ऑपरेंड के बीच संबंधों की जांच करता है।


यदि संबंध सही है, तो यह 1 वापस आता है; यदि संबंध गलत है, तो यह
मान 0 देता है। ऑपरेंड चर, स्थिरांक या अभिव्यक्ति हो सकते हैं।
रिलेशनल ऑपरेटरों का उपयोग निर्णय लेने और लूप में किया जाता है।

Logical Operators are used to combine the res-


ults of two or more conditions. An expression contain-
ing logical operator returns either 0 or 1 depending
upon whether expression results true or false. Logical
operators are commonly used in decision making in C
programming.

Operator Meaning Example Return


value तार्कि क ऑपरेटरों का
&& Logical AND (9>2)&&(17>2) 1
|| Logical OR (9>2) || (17 = = 7) 1 उपयोग दो या अधिक
! Logical NOT 29!=29 0 स्थितियों के परिणामों को
संयोजित करने के लिए किया जाता है। तार्कि क ऑपरेटर युक्त एक
अभिव्यक्ति या तो 0 या 1 वापस आती है जो इस बात पर निर्भर करती है
Logical AND: If any one condition false the कि अभिव्यक्ति का परिणाम सही है या गलत। तार्कि क ऑपरेटरों का
complete condition becomes false. उपयोग आमतौर पर C प्रोग्रामिंग में
Op1 Op2 Op1 && Op2 निर्णय लेने में किया जाता है।
True True True
True False False
False True False
False False False
Logical OR: If any one
condition true the complete
condition becomes true. Op1 Op2 Op1 // Op2
True True True
True False True 10
False True True
False False False
Logical AND: यदि कोई एक शर्त गलत है तो पूरी स्थिति गलत हो pending on the condition. A conditional operator is a
जाती है। ternary operator, that is, it works on 3 operands.
Conditional operator consist of two symbols.
 question mark (?).
 colon ( : ).
Syntax: condition? exp1: exp2;
It first evaluate the condition, if it is true (non-zero)
then the “exp1” is evaluated, if the condition is false
(zero) then the “exp2” is evaluated.
Logical OR: यदि कोई एक शर्त सत्य है तो पूरी शर्त सत्य हो जाती
है। Example:
(A > 100? 0:1);
In above example, if A is greater than 100, 0 is
returned else 1 is returned.

Bitwise Operators: are used to manipulate the


data at bit level. It operates on integers only. It may
not be applied to float. In arithmetic-logic unit
Operator Meaning (which is within the CPU),
Logical NOT: यह ऑपरेटर उस & Bitwise AND mathematical operations like:
अभिव्यक्ति के मूल्य को उलट देता है | Bitwise OR addition, subtraction, multi-
जिस पर वह संचालित होता है यानी, ^ Bitwise XOR plication and division are
<< Shift left done in bit-level which makes
यह एक सही अभिव्यक्ति को गलत processing faster and saves
>> Shift right
और गलत अभिव्यक्ति को सच बनाता ~ One’s complement. power. To perform bit-level
है। operations in C programming,
bitwise operators are used.

Assignment Operators are used to assign a value


(or) an expression (or) a value of a variable to another
variable.
Syntax: variable name = expression (or) value (or)
variable. Ex: x=10;
y=a+b;
z=p; असाइनमेंट ऑपरेटरों का उपयोग किसी अन्य
Compound assign- Operator Example Meaning
ment operator: “C” + = x+=y x=x+y चर को एक मान (या) एक अभिव्यक्ति (या) एक चर
provides compound as- - = x-=y x=x-y का मान असाइन करने के लिए किया जाता है।
signment operators to * = x*=y x=x*y Syntax: variable name = expression (or)
assign a value to vari- / = x/=y x=x/y value (or) variable
able. %= x%=y X=x%y Ex: x=10;
y=a+b;
z=p;
कं पाउंड असाइनमेंट ऑपरेटर: “C” चर को एक मूल्य असाइन करने
के लिए कं पाउंड असाइनमेंट ऑपरेटर प्रदान करता है।

Conditional Operator/ Ternary operator


checks the condition and executes the statement de-

11
The output of bitwise OR is 1 if at least one
corresponding bit of two operands is 1. In C
Programming, bitwise OR operator is denoted by |.
कं डीशनल ऑपरेटर / टर्नेरी ऑपरेटर स्थिति की जांच करता है Bitwise XOR (exclusive OR) operator ^
The result of bitwise XOR operator is 1 if the
और स्थिति के आधार पर स्टेटमेंट निष्पादित करता है। एक कं डीशनल
corresponding bits of two operands are opposite. It is
ऑपरेटर एक टर्नेरी ऑपरेटर है, अर्थात, यह 3 ऑपरेंड पर काम करता denoted by ^.
है। कं डीशनल ऑपरेटर में दो प्रतीक होते हैं:
Bitwise complement operator (~)
 प्रश्न चिह्न (?) Bitwise compliment operator is an unary operator
 कोलन (:) (works on only one operand). It changes 1 to 0 and 0
Syntax: condition? exp1: exp2; to 1. It is denoted by ~.
यह पहले स्थिति का मूल्यांकन करता है, यदि यह सही है (गैर-शून्य) तो
Right Shift Operator
"exp1" का मूल्यांकन किया जाता है, यदि स्थिति गलत (शून्य) है तो Right shift operator shifts all bits towards right by cer-
"exp 2" का मूल्यांकन किया जाता है। tain number of specified bits. It is denoted by >>.

उदाहरण: (A> 100? 0: 1); उपरोक्त उदाहरण में, यदि A 100 से Left Shift Operator
अधिक है, तो 0 वापस कर दिया जाता है अन्यथा 1 वापस कर दिया Left shift operator shifts all bits towards left by cer-
जाता है। tain number of specified bits. It is denoted by <<.

बिटवाइज ऑपरेटर: बिट स्तर पर डेटा में हेरफे र करने के लिए Special Operators
उपयोग किया जाता है। यह के वल पूर्णांक पर काम करता है। यह 1) Comma Operator: The comma operator is used to
फ्लोट पर लागू नहीं किया जा सकता है। अरिथमेटिक लॉजिक separate the statement elements such as variables,
यूनिट (जो सीपीयू के भीतर है) में, गणितीय संचालन जैसे: जोड़, घटाव, constants or expressions, and this operator is used to
link the related expressions together, such expressions
गुणा और विभाजन बिट-स्तर में किए जाते हैं जो प्रसंस्करण को तेज can be evaluated from left to right and the value of
बनाता है और बिजली बचाता है। सी प्रोग्रामिंग में बिट-स्तरीय संचालन right most expressions is the value of combined ex-
करने के लिए, बिटवाइज ऑपरेटरों का उपयोग किया जाता है। pressions
Ex: val(a=3, b=9, c=77, a+c)
First asigns the value 3 to a, then assigns 9 to b, then
assigns 77 to c, and finaly80 (3+77) to value.

2) sizeof Operator: The sizeof() is a unary operator,


that returns the length in bytes of the specified
variable, and it is very useful to find the bytes
occupied by the specified variable in the memory.
Syntax: sizeof(variable-name);
int a;
Bitwise AND operator (&) Ex: sizeof(a); //OUTPUT-----2bytes
The output of bitwise AND is 1 if the corresponding
bits of two operands is 1. If either bit of an operand is बिटवाइज AND ऑपरेटर (&)
0, the result of corresponding bit is evaluated to 0.
Let us suppose the bitwise AND operation of two in- बिटवाइज और का आउटपुट 1 है यदि दो ऑपरेंड के संबंधित बिट्स 1 हैं।
tegers 12 and 25. यदि किसी ऑपरेंड का बिट 0 है, तो संबंधित बिट के परिणाम का
12 = 00001100 (In Binary)
25 = 00011001 (In Binary)
Bit Operation of 12 and 25
00001100
& 00011001
00001000 = 8 (In decimal)
Bitwise OR operator (|) मूल्यांकन 0 पर किया जाता है। आइए हम दो पूर्णांक 12 और 25 के
बिटवाइज AND ऑपरेशन को मान लें।
12
बिटवाइज OR ऑपरेटर (|) बिटवाइज OR का आउटपुट 1 है यदि दो
ऑपरेंड का कम से कम एक संबंधित बिट 1 है। C Programming में,
bitwise OR ऑपरेटर को (|) द्वारा निरूपित किया जाता है।

बिटवाइज XOR(XOR) ऑपरेटर ^ बिटवाइज एक्सओआर ऑपरेटर


का परिणाम 1 है यदि दो ऑपरेंड के संबंधित बिट्स विपरीत हैं। इसे ^द्वारा
निरूपित किया जाता है।

बिटवाइज कॉम्प्लीमेंट ऑपरेटर (~) बिटवाइज कॉम्प्लीमेंट ऑपरेटर


एक युनरी ऑपरेटर है (के वल एक ऑपरेंड पर काम करता है)। यह 1 से 0
और 0 से 1 में बदल जाता है। इसे ~ द्वारा निरूपित किया जाता है।

राइट शिफ्ट ऑपरेटर राइट शिफ्ट ऑपरेटर सभी बिट्स को निर्दिष्ट बिट्स
की निश्चित संख्या से दाईं ओर स्थानांतरित करता है। इसे >> द्वारा निरूपित
किया जाता है।

लेफ्ट शिफ्ट ऑपरेटर लेफ्ट शिफ्ट ऑपरेटर सभी बिट्स को निर्दिष्ट बिट्स
की निश्चित संख्या द्वारा बाईं ओर स्थानांतरित करता है। इसे << द्वारा
निरूपित किया जाता है।

विशेष ऑपरेटर
1) अल्पविराम ऑपरेटर: अल्पविराम ऑपरेटर का उपयोग चर, स्थिरांक
या अभिव्यक्ति जैसे कथन तत्वों को अलग करने के लिए किया जाता है,
और इस ऑपरेटर का उपयोग संबंधित अभिव्यक्तियों को एक साथ जोड़ने
के लिए किया जाता है, ऐसे अभिव्यक्तियों का मूल्यांकन बाएं से दाएं किया
जा सकता है और सबसे अधिक दाएं अभिव्यक्ति का मूल्य संयुक्त
अभिव्यक्तियों का मूल्य है। val(a=3,b = 9, c = 77, a + c) पहले मान
3 को a पर असाइन करता है, फिर 9 से b को असाइन करता है, फिर c को
77 और अंतिम 80 (3 + 77) मान देता है।

2) sizeof ऑपरेटर: sizeof () एक युनरी ऑपरेटर है, जो निर्दिष्ट चर के


बाइट्स में लंबाई लौटाता है, और मेमोरी में निर्दिष्ट चर द्वारा कब्जा किए गए
बाइट्स को ढूंढना बहुत उपयोगी है।
सिंटैक्स: (चर-नाम); यह सच है;
उदाहरण: sizeof(a); //OUTPUT-----2 bytes
Operator Precedence and Associativity

13
Operator precedence determines which operation is and % (Modulus) operators have the same precedence,
Operator Description Associativity
() Parentheses (function call) (see Note) left-to-right
[] Brackets (array subscript)
. Member selection via object name
-> Member selection via pointer
++ -- Postfix increment/decrement (see Note)
++ -- Prefix increment/decrement right-to-left
+- Unary plus/minus
!~ Logical negation/bitwise complement
(type) Cast (convert value to temporary value of type)
* Dereference
& Address (of operand)
sizeof Determine size in bytes on this implementation
*/% Multiplication/division/modulus left-to-right
+- Addition/subtraction left-to-right
<< >> Bitwise shift left, Bitwise shift right left-to-right
< <= Relational less than/less than or equal to left-to-right
> >= Relational greater than/greater than or equal to
== != Relational is equal to/is not equal to left-to-right
& Bitwise AND left-to-right
^ Bitwise exclusive OR left-to-right
| Bitwise inclusive OR left-to-right
&& Logical AND left-to-right
|| Logical OR left-to-right
?: Ternary conditional right-to-left
= Assignment right-to-left
+= -= Addition/subtraction assignment
*= /= Multiplication/division assignment
%= &= Modulus/bitwise AND assignment
^= |= Bitwise exclusive/inclusive OR assignment
<<= >>= Bitwise shift left/right assignment
, Comma (separate expressions) left-to-right
Note: Parentheses are also used to group sub-expressions to force a different precedence; such parenthetical expres-
sions can be nested and are evaluated from inner to outer. Postfix increment/decrement have high precedence, but the
actual increment or decrement of the operand is delayed (to be accomplished sometime before the statement completes
execution). So in the statement y = x * z++; the current value of z is used to evaluate the expression (i.e., z++ evaluates
to z) and z only incremented after all else is done.
performed first in an expression with more than one so the order of evaluation will be decided by associ-
operator with different precedence. For example, x = 7 ativity. According to the given table, the associativity
+ 3 * 2; here, x is assigned 13, not 20 because operator of the multiplicative operators is from Left to
Right. So, First / operator will be evaluated i.e (100 /
* has a higher precedence than +, so it first gets
5) is done, then expression will be 20 % 2. Now, the
multiplied with 3*2 and then adds into 7. % operator will be evaluated and result will be 0.
Operator associativity is used when two operators of ऑपरेटर वरीयता और संबद्धता
the same precedence appear in an expression. Associ-
ativity can be either from Left to Right or Right to ऑपरेटर वरीयता यह निर्धारित करती है कि अलग-अलग वरीयता वाले
Left. For example, 100 / 5 % 2; here both / (division) एक से अधिक ऑपरेटर के साथ अभिव्यक्ति में कौन सा ऑपरेशन पहले
14
किया जाता है। उदाहरण के लिए, X= 7 + 3 * 2; यहां, X को 13 quence in C language is a sequence of characters
असाइन किया गया है, न कि 20 क्योंकि ऑपरेटर * की वरीयता + की that doesn't represent itself when used inside string
literal or character. It is composed of two or more
तुलना में अधिक है, इसलिए इसे पहले 3 * 2 से गुणा किया जाता है और characters starting with backslash.
फिर 7 में जोड़ा जाता है। List of Escape Sequences in C:
ऑपरेटर एसोसिएशन का उपयोग तब किया जाता है जब एक ही वरीयता के
दो ऑपरेटर एक अभिव्यक्ति में दिखाई देते हैं। संबद्धता या तो बाएं से दाएं या
दाएं से बाएं हो सकती है। उदाहरण के लिए, 100 / 5 % 2; यहां / (डिवीजन)
और % (modulus) ऑपरेटरों दोनों की एक ही वरीयता है, इसलिए
मूल्यांकन का क्रम संबद्धता द्वारा तय किया जाएगा। दी गई तालिका के
अनुसार, गुणक ऑपरेटरों की संबद्धता बाएं से दाएं है। इसलिए, पहले /
ऑपरेटर का मूल्यांकन किया जाएगा यानी (100 / 5) किया जाता है, फिर
अभिव्यक्ति 20% 2 होगी। अब, % ऑपरेटर का मूल्यांकन किया जाएगा और
परिणाम 0 होगा।
9. ESCAPE SEQUENCE IN C
An
es- Escape विवरण:
cape Sequence Name Description
se- Alarm or इसका उपयोग सी प्रोग्राम में घंटी जैसी ध्वनि
It is used to generate a bell
\a
Beep sound in the C program. उत्पन्न करने के लिए किया जाता है।
It is used to move the cursor इसका उपयोग कर्सर को एक स्थान पीछे ले
\b Backspace
one place backward. जाने के लिए किया जाता है।
It is used to move the cursor to इसका उपयोग कर्सर को अगले तार्कि क पृष्ठ
\f Form Feed the start of the next logical की शुरुआत में ले जाने के लिए किया जाता
page. है।
It moves the cursor to the start यह कर्सर को अगली लाइन की शुरुआत में
\n New Line
of the next line. ले जाता है।
Carriage It moves the cursor to the start यह कर्सर को वर्तमान लाइन की शुरुआत में
\r
Return of the current line. ले जाता है।
It inserts some whitespace to यह कर्सर के बाईंओर कु छ व्हाइटस्पेस
Horizontal डालता है और कर्सर को तदनुसार
\t the left of the cursor and
Tab
moves the cursor accordingly. स्थानांतरित करता है।
It is used to insert vertical इसका उपयोग ऊर्ध्वाधर स्थान डालने के
\v Vertical Tab
space. लिए किया जाता है।
Use to insert backslash बैकस्लैश वर्ण सम्मिलित करने के लिए
\\ Backlash
character. उपयोग करें.
It is used to display a single इसका उपयोग एकल उद्धरण चिह्न प्रदर्शित
\’ Single Quote
quotation mark. करने के लिए किया जाता है।
Double It is used to display double इसका उपयोग दोहरे उद्धरण चिह्न प्रदर्शित
\”
Quote quotation marks. करने के लिए किया जाता है।
Question It is used to display a question इसका उपयोग प्रश्न चिह्न प्रदर्शित करने के
\?
Mark mark. लिए किया जाता है।
Octal It is used to represent an octal इसका उपयोग एक अष्टक संख्या का
\ooo
Number number. प्रतिनिधित्व करने के लिए किया जाता है।
Hexadecimal It represents the hexadecimal यह हेक्साडेसिमल संख्या का प्रतिनिधित्व
\xhh
Number number. करता है।
15
It represents the NULL यह NULL वर्ण का प्रतिनिधित्व करता है।
\0 NULL
character.
9. ESCAPE SEQUENCE IN C
एक एस्के प अनुक्रम वर्णों का एक अनुक्रम है जो स्ट्रिंग शाब्दिक या
चरित्र के अंदर उपयोग किए जाने पर 10.DATA TYPES IN C
स्वयं का प्रतिनिधित्व नहीं करता है। Data Type For Minimal Range S Si To store data the program
यह बैकस्लैश से शुरू होने वाले दो या mat iz ze must reserve space which is
Spe- e in done using datatype. A
दो से अधिक वर्णों से बना है। datatype is a keyword/pre-
cifie i b
defined instruction used for
C में एस्के प अनुक्रमों की सूची: r n yt allocating memory for data.
b es A data type specifies the
it type of data that a variable
unsigned %c 0 to 255 8 1 can store such as integer,
floating, character etc. It
char
used for declaring/defining
char %c -127 to 127 8 1 variables or functions of
different types before to
signed char %c -127 to 127 8 1 use in a program.
int %d, -32,767 to 32,767 1 2
%i 6
unsigned int %u 0 to 65,535 1 2
6
signed int %d, -32,767 to 32,767 1 2
%i (same as int) 6
short int %hd -32,767 to 32,767 1 2
6
unsigned %hu 0 to 65,535 1 2
short int 6
signed short %hd Same as short int 1 2
int 6
long int %ld, -2,147,483,647 to 3 4
%li 2,147,483,647 2
long long %lld -(2^63) to (2^63)-1 6 8
int , 4
%lli
signed long %ld, Same as long int 3 4
int %li 2
unsigned %lu 0 to 4,294,967,295 3 4
long int 2
unsigned %llu 0 to 6 8
long long 18,446,744,073,70 4
int 9,551,615
float %f 1.2E-38 to 3 4
3.4E+38 2
double %lf 1.7E-308 to 6 8
1.7E+308 4
long double %Lf 3.4E-4932 to 1 16
1.1E+4932 6
Program to declare variables and print their value

#include<stdio.h>
#include<conio .h>
void main()
{
//Create variables
10. C के डाटा टाइप्स int myNum = 5; // Integer (whole number)
//Program for taking
float myFloatNum = 5.99; // Floating point numb
डेटा संग्रहीत करने के लिए प्रोग्राम के स्थान को आरक्षित करना होगा जो user
char myLetter = 'D'; // Character
डेटाटाइप का उपयोग करके किया जाता है। डेटाटाइप एक कीवर्ड #include<stdio>
clrscr();
/पूर्वनिर्धारित निर्देश है जिसका उपयोग डेटा के लिए मेमोरी आवंटित करने के void main()
// Print variables
लिए किया जाता है। एक डेटा प्रकार उस डेटा के प्रकार को निर्दिष्ट करता है {
printf("%d\n", myNum);
जिसे एक चर संग्रहीत कर सकता है जैसे पूर्णांक, फ्लोटिंग, वर्ण आदि। यह int x;
printf("%f\n", myFloatNum);
एक प्रोग्राम में उपयोग करने से पहले विभिन्न प्रकार के चर या कार्यों को clrscr();
printf("%c\n", myLetter);
घोषित करने / परिभाषित करने के लिए उपयोग किया जाता है। printf("Enter a numbe
getch();
scanf("%d", &x);
}
printf("The number is
getch();
}

11. RECEIVING INPUT FROM THE


USER
In order to take input from the user and assign it to
a variable, we use scanf function.
Syntax for using scanf:
Scanf (“%d”, &i); (& is important!)
& is the “address of” operator and it means that the
supplied value should be copied to the address
which is indicated by variable i.

// program for taking multiple values from


user
#include<stdio>
void main()
{
int x,y;
clrscr();
printf("Enter the numbers:");
scanf("%d%d", &x,&y);
printf("x is %d", x);
printf("y is %d", x);
getch();
}
17
Types of Instructions –
1. Type declaration Instruction
2. Arithmetic Instruction
3. Control Instruction
//Program for calculating sum=x+y+z;
Type declaration Instruction –
#include<stdio>  int a;
void main()  float b;
{ Other variations:
int x=10,y=20,z=30,sum;  int i=10; int j=i; int a=2;
clrscr();  int j1=a+1-i;
sum=x+y+z;  float b=a+3; float a=1.1; (ERROR! as we
printf("The sum is %d", sum); are trying to use ‘a’ before defining it)
 int a,b,c,d;
getch();
a=b=c=d=30;
} Value of a, b, c & d will be 30 each
Arithmetic Instruction –
 int i=(3*2)+1
Here *, + are operator and 3, 2, 1 are operands.
11. उपयोगकर्ता से इनपुट प्राप्त करना Operands can be int, float etc. +, -, *, / are
arithmetic operators.
उपयोगकर्ता से इनपुट लेने और इसे एक चर को असाइन करने के लिए, हम  int b=2, c=3;
स्कै नफ फ़ं क्शन का उपयोग करते हैं। scanf का उपयोग करने के लिए :  int z; Z=b*c; (This is legal)
सिंटैक्स:  int Z; b*c=z; (This is Illegal Not allowed)
Scanf (“%d”, &i); (&महत्वपूर्ण है!) “%” is Modular division operator, it returns the
& “ऑपरेटर का पता है” और इसका मतलब है कि आपूर्ति किए गए मूल्य remainder and cannot be applied on float values or
variables and sign will be same as that of
को उस पते पर कॉपी किया जाना चाहिए जो चर i द्वारा इंगित किया गया है।
numerator.
Example:
 5%2=1
 int a=10, b=4
int c=a%b;
then value of
// program for taking multiple values from  -5%2=-1
user and calculating sum. (sum=x+y+z)
#include<stdio> Note -:
void main() 1) No operator is assume to be present
int i = ab (Invalid)
{
int i = a*b (Valid)
int x,y,z,sum;
2) There is no operator to perform exponentia-
clrscr(); tion in C However we can use pow(x,y)
printf("Enter the numbers:"); from <math.h>(More later)
scanf("%d%d%d", &x,&y,&z);
sum=x+y+z;
print(“sum of %d, %d, %d is %d”,
x,y,z,sum);
getch();
Instructions
A C program is a set of instructions. Just like a
recipe – Which contains instructions to prepare a
निर्देश
particular Dish.

18
एक C कार्यक्रम निर्देशों का एक सेट है। एक नुस्खा की तरह - जिसमें
एक विशेष पकवान तैयार करने के निर्देश शामिल हैं।
निर्देशों के प्रकार –
I. टाइप डिक्लेरेशन निर्देश
II. अंकगणितीय निर्देश
III. नियंत्रण निर्देश
टाइप डिक्लेरेशन इंस्ट्रक्शन –
 int a;
 float b;
अन्य विविधताएं:
 int i=10; int j=i; int a=2;
 int j1=a+1-i;
 float b=a+3; float a=1.1; (भूल! क्योंकि हम
‘a’ को परिभाषित करने से पहले ‘a’ का उपयोग करने की
कोशिश कर रहे हैं)
 int a,b,c,d;
a=b=c=d=30; (a, b, c, और d प्रत्येक का मान
30 होगा)

अंकगणित निर्देश –
int i=(3*2)+1(*/+ ऑपरेटर है और 3,2,1 ऑपरेंड है)
ऑपरेंड इंट/फ्लोट आदि हो सकते हैं+ - * / अंकगणितीय ऑपरेटर हैं।
int b=z, c=3;
int z; Z=b*c; (ऐसा कर सकते हैं )
int Z; b*c=z; (अवैध (अनुमति नहीं है)))
मॉड्यूलर डिवीजन ऑपरेटर भाग करने पे शेषफल देता है, फ्लोट पर
लागू नहीं किया जा सकता चिह्न प्रगणक के समान है।

नोट-:
I. किसी भी ऑपरेटर को उपस्थित नहीं माना जाता है।
int i = ab (अमान्य)
int i = a*b (वैध)
II. C में प्रतिपादक प्रदर्शन करने के लिए कोई ऑपरेटर नहीं है,
हालांकि हम (बाद में) pow (x, y) का उपयोग कर सकते हैं
<math.h> से।

19
CHAPTER 2- FLOW CONTROL STATEMENTS

 DECISION CONTROL STATEMENTS


 IF
 IF-ELSE
 NESTED IF-ELSE
 SWITCH CASE
 LOOP CONTROL STATEMENTS
 FOR
 WHILE
 DO-WHILE
 UNCONDITIONAL CONTROL STATEMENTS
 BREAK
 CONTINUE
 GOTO

20
CONDITIONAL INSTRUCTIONS कं डीशनल(सशर्त) निर्देश
o Sometimes we want to watch comedy o कभी-कभी हम यूट्यूब पर कॉमेडी वीडियो देखना चाहते हैं अगर
videos on you Tube if the day is Sunday. दिन रविवार है।
o Sometimes we order junk food if it is our
o कभी-कभी हम हॉस्टल में अपने दोस्त का जन्मदिन होने पर जंक
friend’s birthday in the hostel.
o You might want to buy an umbrella if it’s फू ड ऑर्डर करते हैं।
raining and you have the money. o यदि बारिश हो रही है और आपके पास पैसा है तो आप छाता
o You order the meal if dal or your favorite खरीदना चाह सकते हैं।
bhindi is listed on the menu. o यदि दाल या आपका पसंदीदा मेनू पर सूचीबद्ध है तो आप भोजन
All these are decisions which depends on a का आदेश देते हैं।
condition being met.
In C language too, we must be alert to execute
ये सभी निर्णय हैं जो एक शर्त को पूरा करने पर निर्भर करते हैं। सी भाषा
instructions on a condition (s) being met. में भी, हमें एक शर्त (s) को पूरा करने पर निर्देशों को निष्पादित करने के
लिए तैयार होना चाहिए।
DECISION MAKING INSTRUCTIONS C में निर्णय लेने के निर्देश
IN C
 if (अगर/यदि) कथन
 if statement
 if – else statement  if-else(यदि-तो) कथन
 Switch statement  स्विच कथन
if (अगर) कथन –
if statement – यदि कथन सशर्त शाखाओं को नियंत्रित करता है। यदि किसी कथन का
The if statement controls conditional branching.
मुख्य भाग निष्पादित किया जाता है यदि अभिव्यक्ति का मान शून्य नहीं
The body of an if statement is executed if the value
of the expression is nonzero. Or if statement is है। या यदि शर्त सही होने पर कोड को निष्पादित करने के लिए कथन का
used to execute the code if condition is true. If the उपयोग किया जाता है। यदि अभिव्यक्ति / स्थिति का मूल्यांकन गलत
expression/condition is evaluated to false (0), (0) के लिए किया जाता है, तो if के अंदर के बयानों को निष्पादन से
statements inside the body of if is skipped from
execution.
छोड़ दिया जाता है।
The syntax of an if statement in C looks like: C में if स्टेटमेंट का सिंटेक्स इस प्रकार दिखता है:
If the condition/expression is true, then the true state-
ment will be executed otherwise the true statement

Code example/उदाहरण:
Syntax:
int a = 23;
if (Condition/expression)
if(a>18)
{ {
true statement; printf(“You can drive \n”);
} }
statement-x;

यदि शर्त / अभिव्यक्ति सही है, तो सही कथन निष्पादित किया जाएगा
block will be skipped and the execution will jump to
अन्यथा सही कथन ब्लॉक को छोड़ दिया जाएगा और निष्पादन
the statement-x. The “true statement” may be a single statement-x पर पहुंच जाएगा। “true statement” एक एकल कथन
statement or group of statement. If there is only one या कथन का समूह हो सकता है। यदि ब्लॉक में के वल एक कथन है, तो
statement in the if block, then the braces are optional.
ब्रेसिज़ वैकल्पिक हैं। लेकिन अगर एक से अधिक बयान हैं तो ब्रेसिज़
But if there is more than one statement the braces are
compulsory. अनिवार्य हैं।

21
if-else statement- अगर-अन्य कथन -
The if-else statement is an extension of the simple if if-else कथन if कथन का विस्तार है। if-else कथन कु छ कोड
statement. The if...else statement executes some निष्पादित करता है यदि परीक्षण अभिव्यक्ति सही है (नॉनज़ीरो) और
code if the test expression is true (nonzero) and
some other code if the test expression is false (0).
कु छ अन्य कोड यदि परीक्षण अभिव्यक्ति गलत है (0)।

Syntax : Code Example:


if (condition) int number;
{ printf("Enter an integer: ");
Statement1;
scanf("%d",&number);
}
if( number%2 == 0 )
else
{ printf("%d is an even integer.",number);
Statement2; else
} printf("%d is an odd integer.",number);
Next_statement;
यदि if का शर्त सत्य है, तो statement1 और next_statement
If the condition is true, then the statement1 and
Next-statement will be executed and if the condition
निष्पादित किया जाएगा और यदि शर्त झूठी है, तो statement2 और
is false, then the statement2 and Next-statement is next_statement निष्पादित किया जाता है।
executed. या
Or
If test expression is true, codes inside the body of if
यदि परीक्षण अभिव्यक्ति सही है, तो if के अंदर कोड को निष्पादित
statement is executed and, codes inside the body of किया जाता है और, else कथन के अंदर के कोड को छोड़ दिया जाता
else statement is skipped. If test expression is false, है। यदि परीक्षण अभिव्यक्ति झूठी है, तो else कथन के अंदर के कोड को
codes inside the body of else statement is executed
and, codes inside the body of if statement is निष्पादित किया जाता हैं और, if कथन के अंदर के कोड को छोड़
skipped. दिया जाता है।
नेस्टेड अगर-अन्य कथन
Nested if-else statement यदि निर्णयों की एक श्रृंखला शामिल है, तो हमें नेस्टेड फॉर्म में अगर-
When a series of decisions are involved, we may
अन्य कथन से अधिक उपयोग करना पड़ सकता है। यदि -अन्यथा
have to use more than on if-else statement in nested
form. If –else statements can also be nested inside बयानों को ब्लॉक या ब्लॉक या दोनों होने पर दूसरे के अंदर भी नेस्टेड
another if block or else block or both. किया जा सकता है।

Syntax: if(condition-1)
{
if (condition-2)
{ 22
statement-1;
अन्य-अगर सीढ़ी –
यदि और कथन का उपयोग कई स्थितियों से एक कोड को निष्पादित
करने के लिए किया जाता है।

If the condition-1 is false, the statement-3 and state-


ment-x will be executed. Otherwise it continues to
perform the second test. If the condition-2 is true,
the true statement-1 will be executed otherwise the
statement-2 will be executed and then the control is
transferred to the statement-x.

Else if ladder-
The if else-if statement is used to execute one code
Syntax :
from multiple conditions.
if( condition-1) Code
{ int
statement-1; if (
यदि } p
शर्त else if(condition-2) else
-1 { p
statement-2; else
} p
else if(condition-3) else
{ p
statement-3; else
} p
else if(condition-n) else
{ p
statement-n; else
} p
else
{
गलत है, तो कथन -3 और कथन -x निष्पादित किया जाएगा। अन्यथा
यह दूसरा परीक्षण करना जारी रखता है। यदि शर्त -2 सत्य है, तो कथन - default-statement;
1 निष्पादित किया जाएगा अन्यथा कथन -2 निष्पादित किया जाएगा }
और फिर कथन-x में स्थानांतरित कर दिया जाएगा। statement-x;

23
The expression following the keyword switch is
Switch case– Syntax:
Switch – case is used when we have to make a
choice between numbers of alternatives for a given switch(expression)
variable. {
case value-1:
statement/block-1;
Start
break;
The Switch case value-2:
Statement statement/block t-2;
Expression
break;
case value-3:
Expression = value-1 statement/block -3;
Block- break;
1 case value-4:
Expression = value-2 statement/block -3;
Block- break;
2 default:
Expression = value-n
Block- default- statement/block t;
n break ;
Default (no match) }
Default
code any expression that must yield an integer value. It
Rest of code must be integer constants like 1, 2, and 3. The
keyword case is followed by an integer or a charac-
ter constant, each constant in each must be different
from all the other.
First the integer expression following the keyword
switch is evaluated. The value it gives is searched
against the constant values that follow the case
statements. When a match is found, the program ex-
ecutes the statements following the case. If no
match is found with any of the case statements, then
the statements following the default are executed.

Valid Switch Invalid Switch Valid Case Invalid Case

switch(x) switch(f) case 3; case 2.5;


switch(x>y) switch(x+2.5) case 'a'; case x;
switch(a+b-2) case 1+2; case x+2;
switch(func(x,y)) case 'x'>'y'; case 1,2,3;

Rules for writing switch() statement.


1. The expression in switch statement must be
an integer value or a character constant.
2. No real numbers are used in an expression.
स्विच के स- 3. The default is optional and can be placed
स्विच - के स का उपयोग तब किया जाता है जब हमें किसी दिए गए चर anywhere, but usually placed at end.
4. The case keyword must terminate with
के लिए बहुत सारे विकल्पों में से एक चयन करना होता है। colon (:).
5. No two case constants are identical.
6. The case labels must be constants.
24
7. When a break statement is 7. जब एक ब्रेक स्टेटमेंट पहुंच
reached, the switch termin- Code example: जाता है, तो
ates, and the flow of con- int num = 8; स्विच समाप्त हो
trol jumps to the next line switch (num)
following the switch state- जाता है, और
{
ment. स्विच स्टेटमेंट
Note: case 7:
के बाद नियंत्रण
It isn't necessary to use break after printf("Value is 7");
का प्रवाह
each block, but if you do not use it, break;
अगली पंक्ति में
all the consecutive block of codes case 8:
will get executed after the कू द जाता है।
printf("Value is 8");
matching block. नोट:
break;
case 9:
प्रत्येक ब्लॉक के बाद ब्रेक का उपयोग
printf("Value is 9"); करना आवश्यक नहीं है, लेकिन यदि आप
break; इसका उपयोग नहीं करते हैं, तो मिलान
default: ब्लॉक के बाद कोड के सभी लगातार
printf("Out of range"); ब्लॉक निष्पादित हो जाएंगे।
break;
}

कीवर्ड स्विच के बाद की अभिव्यक्ति कोई भी अभिव्यक्ति है जिसे


पूर्णांक मान प्राप्त करना चाहिए। यह 1, 2 और 3 जैसे पूर्णांक स्थिरांक
होना चाहिए। कीवर्ड के स के बाद एक पूर्णांक या एक वर्ण स्थिरांक होता
है, प्रत्येक में प्रत्येक स्थिरांक अन्य सभी से अलग होना चाहिए। सबसे
पहले कीवर्ड स्विच के बाद पूर्णांक अभिव्यक्ति का मूल्यांकन किया
जाता है। यह जो मान देता है उसे के स स्टेटमेंट का पालन करने वाले Loop Control Instructions
निरंतर मूल्यों के खिलाफ खोजा जाता है। जब कोई मिलान पाया जाता Why Loops –
है, तो प्रोग्राम मामले के बाद बयानों को निष्पादित करता है। यदि किसी Sometimes we want our programs to execute few
भी मामले के बयान के साथ कोई मेल नहीं पाया जाता है, तो डिफ़ॉल्ट set of instructions over and over again for ex:
को निष्पादित किया जाता हैं। printing 1 to 100, first 100 even numbers etc.
Hence loops make it easy for a programmer to tell
computer that a given set of instructions must be
executed repeatedly.
Types of loops –
In computer programming, a loop is a sequence of
instructions that is repeated until a certain condition
is reached.
There are mainly two types of loops:
स्विच () कथन लिखने के नियम Entry Controlled loops: In this type of loops the test
1. स्विच कथन में अभिव्यक्ति एक पूर्णांक मान या एक वर्ण स्थिरांक होना condition is tested before entering the loop body.
“For” Loop and “While” Loops are entry controlled
चाहिए। loops.
2. एक अभिव्यक्ति में कोई वास्तविक संख्या का उपयोग नहीं किया जाता है। Exit Controlled Loops: In this type of loops the test
3. डिफ़ॉल्ट वैकल्पिक है और इसे कहीं भी रखा जा सकता है, लेकिन condition is tested or evaluated at the end of loop
आमतौर पर अंत में रखा जाता है। body. Therefore, the loop body will execute atleast
once, irrespective of whether the test condition is
4. के स कीवर्ड को कोलन(:)के साथ समाप्त होना चाहिए। true or false. “do–while” loop is exit controlled
5. कोई भी दो के स स्थिरांक समान नहीं हैं। loop.
6. के स लेबल स्थिरांक होना चाहिए।
25
A looping process would include the following एक लूपिंग प्रक्रिया में निम्नलिखित चार चरण शामिल होंगे:
four steps. 1. लूप काउंटर चर को प्रारंभिक मान पर सेट करना।
1. Setting the loop counter variable to an initial
value. 2. स्थिति का परीक्षण करें।
2. Test the condition. 3.
3. Executing the body of the 3.
loop depending on the
condition. 3.
4. Updating the condition 3.
variable. 3.
for loop: 3.
 In this loop structure, more 3.
than one variable can be ini- 3.
tialized.
3.
 One of the most important
features of this loop is that 3.
the three actions can be taken 3.
at a time like variable initial- 3.
ization, condition checking
and increment/decrement. 3.
 The for loop is more concise 3.
and flexible than that of 3.
while and do-while loops.
3.
Syntax : स्थिति के आधार पर लूप के शरीर को निष्पादित करना।
for(initialization; condition; increment/decrement)
4. चर के मान को बदलना ।
{
Statements; //body of for loop फॉर लूप:
}
लूप नियंत्रण निर्देश  इस लूप संरचना में, एक से अधिक
क्यों लूप – चर का मान शुरू किया जा सकते
कभी-कभी हम चाहते हैं कि हमारे प्रोग्राम में निर्देशों के कु छ सेट को हैं।
बार-बार निष्पादित करें, जैसे : 1 से 100, पहले 100 सम संख्या ओं को  इस लूप की सबसे महत्वपूर्ण
विशेषताओं में से एक यह है कि
प्रिंट करना आदि। इसलिए लूप एक प्रोग्रामर के लिए कं प्यूटर को यह
तीन कार्यों को एक समय में लिया
बताना आसान बनाते हैं कि निर्देशों के एक दिए गए सेट को बार-बार जा सकता है जैसे चर का प्रारंभिक
निष्पादित किया जाना चाहिए। मान, चर के मान की स्थिति की
लूप के प्रकार - कं प्यूटर प्रोग्रामिंग में, एक लूप, निर्देशों का एक अनुक्रम जांच और चर का मान को अपडेट
है जिसे एक निश्चित स्थिति तक पहुंचने तक दोहराया जाता है। करना।
लूप मुख्य रूप से दो प्रकार के होते हैं:  फॉर लूप, while और do-while
प्रवेश नियंत्रित लूप: इस प्रकार के लूप में लूप बॉडी में प्रवेश करने से लूप की तुलना में अधिक संक्षिप्त
पहले परीक्षण स्थिति का परीक्षण किया जाता है। "फॉर" लूप और और लचीला है।
"while" लूप प्रवेश नियंत्रित लूप हैं। Code Example:
निकास नियंत्रित लूप: इस प्रकार के लूप में परीक्षण स्थिति का परीक्षण for(i = 0; i<3 ; i++)
या मूल्यांकन लूप बॉडी के अंत में किया जाता है। इसलिए, लूप बॉडी {
को कम से कम एक बार निष्पादित करेगी, भले ही परीक्षण की स्थिति printf(“ %d ” , i);
सही हो या गलत। "do-while" लूप निकास नियंत्रित लूप है। }
while loop:
Output: 012
26
“while” loop is a most basic loop in C programming. "while" लूप सी प्रोग्रामिंग में सबसे बुनियादी लूप है। "while" लूप में
“while” loop has one control condition, and executes एक नियंत्रण स्थिति होती है, और जब तक स्थिति सही होती है तब तक
as long the condition is true.
The basic format of while loop statement is: निष्पादित होता है। while लूप कथन का मूल प्रारूप है:

Code Example:
Syntax:
i=0;
variable initialization ;
while( i<3 )
while (condition)
{
{
statements ; printf(“ %d ” , i);
variable increment or decrement ; i++;
} }
Output: 012
do-while loop:
The basic format of do-while loop statement is: do-while लूप:
do-while लूप स्टेटमेंट का मूल प्रारूप है:
Syntax:
Code Example:
variable initialization ;
i=0;
do
do
{
{
statements ;
variable increment or decrement ; printf(“ %d ” , i);
} while (condition) ; i++;
} while( i<3 )
Output: 012
UNCONDITIONAL CONTROL STATE-
MENTS बिना शर्त नियंत्रण कथन
In c, there are control statements that do not need सी में, नियंत्रण कथन हैं जिन्हें प्रोग्राम निष्पादन प्रवाह को नियंत्रित
any condition to control the program execution
flow. These control statements are called as uncon- करने के लिए किसी भी शर्त की आवश्यकता नहीं है। इन नियंत्रण
ditional control statements. C programming lan- कथनों को बिना शर्त नियंत्रण कथन कहा जाता है। सी प्रोग्रामिंग भाषा
guage provides the following unconditional control
निम्नलिखित बिना शर्त नियंत्रण कथन प्रदान करती है
statements...
 ब्रेक
 break
 continue  continue(जारी रखना)
 goto
 goto (जाओ);
The break; continue; and goto; statements are ब्रेक, कं टिन्यू, गोटु कथन का उपयोग किसी प्रोग्राम के सामान्य
used to alter the normal flow of a program. प्रवाह को बदलने के लिए किया जाता है। लूप कार्य का एक सेट को
Loops perform a set of repetitive task until text ex-
pression becomes false but it is sometimes desirable बार बार निष्पादित करते हैं जब तक कि पाठ अभिव्यक्ति झूठी नहीं हो
to skip some statement/s inside loop or terminate जाती है, लेकिन कभी-कभी लूप के अंदर कु छ कथन को छोड़ना या
the loop immediately without checking the test ex-
pression. In such cases, break and continue state-
परीक्षण अभिव्यक्ति की जांच किए बिना लूप को तुरंत समाप्त करना
ments are used. वांछनीय होता है। ऐसे मामलों में, ब्रेक और कं टिन्यू का उपयोग किया
जाता है।
while लूप:

27
break statement: name to move the program control to
In C programming, break state- int i; the specified label.
ment is used with conditional if
statement. The break statement is for (i = 0; i < 10; i++) ब्रेक (विराम) कथन:
used to perform the following two { सी प्रोग्रामिंग में, ब्रेक स्टेटमेंट का उपयोग सशर्त यदि
things: if (i == 4) कथन के साथ किया जाता है। ब्रेक स्टेटमेंट का उपयोग
 break statement is used to ter-
minate the switch case state- { निम्नलिखित दो चीजों को करने के लिए किया जाता है:
ment. break;  ब्रेक स्टेटमेंट का उपयोग स्विच के स स्टेटमेंट
 break statement is also used to } को समाप्त करने के लिए किया जाता है।
terminate looping statements
printf("%d\n", i);  ब्रेक स्टेटमेंट का उपयोग लूपिंग स्टेटमेंट को
like while, do-while and for.
}
समाप्त करने के लिए भी किया जाता है जैसे
continue statement: कि while, do-while और for।
It is sometimes desirable to skip some statements
कं टिन्यू कथन:
inside the loop. In such cases, continue statement is
used. Just like break, continue is also used with कभी-कभी लूप के अंदर कु छ बयानों को छोड़ना वांछनीय होता है। ऐसे
conditional if statement. The con- Code example: मामलों में, continue कथन का उपयोग किया जाता है। ब्रेक
tinue statement is used to move the int i; की तरह, कं टीन्यू का उपयोग सशर्त बयान के साथ भी किया
program execution control to the be- जाता है। continue कथन का उपयोग प्रोग्राम निष्पादन
for (i = 0; i < 10; i++)
ginning of the looping statement. नियंत्रण को लूपिंग कथन की शुरुआत में स्थानांतरित करने
{
When the continue statement is en- के लिए किया जाता है। जब लूपिंग स्टेटमेंट में continue
if (i == 4)
countered in a looping statement,
the execution control skips the rest { कथन का सामना किया जाता है, तो निष्पादन नियंत्रण लूपिंग
of the statements in the looping continue; ब्लॉक में बाकी बयानों को छोड़ देता है और सीधे लूप की
block and directly jumps to the be- } शुरुआत में कू द जाता है। continue कथन का उपयोग
ginning of the loop. The con- printf("%d\n", i); लूपिंग कथनों के साथ किया जा सकता है जैसे कि while,
tinue statement can be used with } do-while और for। यदि कोई निर्दिष्ट स्थिति उत्पन्न होती
looping statements like while, do- है, तो continue कथन एक पुनरावृत्ति (लूप में) को तोड़ देता
while and for. The continue state- है, और लूप में अगले पुनरावृत्ति के साथ जारी रहता है।
ment breaks one iteration (in the loop), if a spe-
cified condition occurs, and continues with the next
गोटू कथन:
iteration in the loop. "ब्रेक" और "कं टिन्यू" बयानों के विपरीत, गोटू स्टेटमेंट का उपयोग
प्रोग्राम के भीतर एक विशिष्ट स्थान पर प्रोग्राम नियंत्रण को स्थानांतरित
goto statement: करने के लिए किया जाता है। गोटू स्टेटमेंट का सबसे अधिक उपयोग तब
Unlike the "break" and "continue" statements, the किया जाता है जब हमें प्रोग्राम के सामान्य प्रवाह को बदलने की
goto statement is used to move program control to a आवश्यकता होती है। प्रोग्राम नियंत्रण को प्रोग्राम के किसी अन्य
specific location within the program. The goto अनुभाग में ले जाने के लिए, एक लेबल बनाएँ, और तब प्रोग्राम नियंत्रण
statement is most commonly used when we need to को निर्दिष्ट लेबल पर ले जाने के लिए लेबल नाम के बाद गोटू का
change the program's normal flow. To move the उपयोग करें।
program control to another
Syntax: Code example:
section of the program, cre-
goto label; int i=1;
ate a label, and then use
............. clrscr();
goto followed by the label
............. count: //This is Label
............. printf("%d\n",i);
label: statement; i++;
if(i<=10)
28
{
goto count; //This jumps to label "count:"
CHAPTER 3- ARRAY
 DEFINATION
 DECLARING ONE-D ARRAY
 ACCESSING THE ELEMENTS OF THE ARRAY
 INITIALIZE THE ARRAY
 TWO-D ARRAY DECLARATION
 ACCESSING THE ELEMENTS OF 2D ARRAY
 INITIALIZE THE 2D ARRAY
 STRING
 STRING FUNCTIONS

29
data_type array_name[size] ={v1,v2,…vn/list of
values };

ARRAY ऐरे
Array is the collection of similar data types or col- ऐरे समान डेटा प्रकारों का संग्रह या सन्निहित मेमोरी स्थान में संग्रहीत
lection of similar entity stored in contiguous समान इकाई का संग्रह है। वर्ण की ऐरे एक स्ट्रिंग है। ऐरे के प्रत्येक डेटा
memory location. Array of character is a string.
Each data item of an array is called an element. And आइटम को एक एलिमेंट कहा जाता है। और प्रत्येक एलिमेंट अद्वितीय है
each element is unique and located in separated और अलग-अलग मेमोरी स्थान में स्थित है। एक ऐरे के प्रत्येक तत्व एक
memory location. Each of elements of an array चर साझा करते हैं लेकिन प्रत्येक तत्व में अलग-अलग सूचकांक संख्या
share a variable but each element having different
index no. known as subscript. An array can be a होती है। सबस्क्रिप्ट के रूप में जाना जाता है। एक ऐरे एक एकल
single dimensional or multi-dimensional and num- आयामी या बहु-आयामी हो सकती है और सबस्क्रिप्ट की संख्या इसके
ber of subscripts determines its dimension. And आयाम को निर्धारित करती है। और सबस्क्रिप्ट की संख्या हमेशा शून्य
number of subscript is always starts with zero. One
dimensional array is known as vector and two di- से शुरू होती है। एक आयामी ऐरे को वेक्टर के रूप में जाना जाता है और
mensional arrays are known as matrix. दो आयामी सरणियों को मैट्रिक्स के रूप में जाना जाता है। लाभ: सरणी
Advantages: Array variable can store more than
चर एक समय में एक से अधिक मान संग्रहीत कर सकता है जहां अन्य
one value at a time where other variable can store
one value at a time. चर एक समय में एक मान संग्रहीत कर सकते हैं। नुकसान: सरणी की
Disadvantage: Whatever size, we define at the time घोषणा के समय हम जो भी आकार परिभाषित करते हैं, हम सीमा को
of declaration of array, we can't exceed the limit.
So, it doesn't grow the size dynamically.
पार नहीं कर सकते। तो, यह गतिशील रूप से आकार नहीं बढ़ता है।

Declaration of an Array Declaration of an Array


Syntax: data-type variable-name[size/length of ar- सिंटेक्स: डाटा-का-प्रकार चर-नाम[ऐरे की लंबाई];
ray];
उदाहरण: int arr[10];
For example: int arr[10];
एक ऐरे की घोषणा कं पाइलर
The declaration of an array arr[0] [1] [2] [3] [4] [5] [6] [7] [8] [9] को बताती है कि, डेटा प्रकार,
tells the compiler that, the
data type, name of the array, size of the array and ऐरे का नाम, ऐरे का आकार
for each element it occupies memory space. Like और प्रत्येक एलिमेंट के लिए यह मेमोरी स्पेस पर कब्जा करता है। जैसे
for int data type, it occupies 2 bytes for each ele- कि इंट डेटा प्रकार के लिए, यह प्रत्येक एलिमेंट के लिए 2 बाइट्स पर
ment and for float it occupies 4 byte for each ele-
ment etc. The size of the array operates the number कब्जा कर लेता है और फ्लोट के लिए यह प्रत्येक एलिमेंट आदि के
of elements that can be stored in an array and it may लिए 4 बाइट पर कब्जा कर लेता है। ऐरे का आकार उन एलिमेंट की
be a int constant or constant int expression. संख्या को संचालित करता है जिन्हें ऐरे में संग्रहीत किया जा सकता है
In the above example int is the data type, arr is the और यह एक int कांस्टेंट या कांस्टेंट int अभिव्यक्ति हो सकती है।
name of the array and 10 is the size of array. It उपरोक्त उदाहरण में int डेटा का प्रकार है, arr ऐरे का नाम है और 10
means array arr can only contain 10 elements of int
ऐरे का आकार है। इसका मतलब है कि ऐरे arr में के वल int प्रकार के
type. Index of an array starts from 0 i.e first ele-
ment of arr array will be stored at arr[0] address 10 एलिमेंट हो सकते हैं। एक ऐरे का सूचकांक 0 से शुरू होता है यानी
and last element will occupy arr[9]. arr ऐरे का पहला एलिमेंट arr[0] पते पर संग्रहीत किया जाएगा और
After an array is declared it must be initialized. Oth-
erwise, it will contain garbage value(any random
अंतिम एलिमेंट arr[9] पर कब्जा कर लेगा।
value). An array can be initialized at either compile एक arr घोषित होने के बाद इसे प्रारंभभिक मान दिया जाना चाहिए।
time or at runtime. अन्यथा, इसमें कचरा मूल्य (कोई भी यादृच्छिक मूल्य) होगा। एक ऐरे
Compile time Array initialization को या तो संकलन समय पर या रनटाइम पर प्रारंभ किया जा सकता है।
Compile time initializtion of array elements is same
as ordinary variable initialization. संकलन समय पर ऐरे का प्रारंभिक मान देना
Syntax:

30
ऐरे तत्वों का संकलन समय प्रारंभ सामान्य चर प्रारंभिककरण के समान Eventhough compiler allocates 5 memory loca-
है। सिंटैक्स: data_type array_name[आकार]={v1,v2,... tions, using this declaration statement, the com-
vn/मानों की सूची}; piler initializes first two locations with 10 and
15, the next set of
a[0] a[1] a[2]
memory locations
Example 10 15 0
are automatically
int age[5]={22,25,30,32,35}; 1000 1002 1004
initialized to zero.
int marks[4]={ 67, 87, 56, 0 1 2 3 4
77 }; //integer array initializa- 22 25 30 32 35 उदाहरण
tion int age[5]={22,25,30,32,35};
float area[5]={ 23.4, 6.8, 5.5 }; //float array initial- int marks[4]={67, 87, 56, 77}; //इन्टिजर ऐरे के एलिमेंट्स
ization
int marks[4]={ 67, 87, 56, 77, 59 }; //Compile time को वैल्यू देना
error float area[5]={23.4, 6.8, 5.5}; //फ्लोट ऐरे के एलिमेंट्स को
वैल्यू देना
Different ways of initializing arrays:
marks[4]={67, 87, 56, 77, 59}; // कम्पाइल टाइम एरर
 Initializing all specified memory locations
 Partial array initialization.
 Initialization without size.
ऐरे को प्रारंभ करने के विभिन्न तरीके :
1. Initializing all specified memory locations: If  सभी निर्दिष्ट स्मृति स्थानों को प्रारंभ करना
the number of values to be initialized is equal to
 आंशिक सरणी प्रारंभ।
size of array. Arrays can be initialized at the
time of declaration. Array elements can be ini-  आकार के बिना प्रारंभ।
tialized with data items of type int, float, char, a. सभी निर्दिष्ट स्मृति स्थानों को प्रारंभ करना: यदि प्रारंभ किए
etc. जाने वाले मानों की संख्या सरणी के आकार के बराबर है. घोषणा के
Ex: consider integer initialization
समय सरणी शुरू की जा सकती है। सरणी तत्वों को प्रकार int,
int a[5]={10,20,30,40,50};
During compilation, 5 contiguous memory loca- फ्लोट, char, आदि के डेटा आइटम के साथ शुरू किया जा सकता
tions are reserved by the compiler for the vari- है।
able a and all these locations are initialized. उदाहरण: इन्टिजर ऐरे प्रारंभिक मान
The array a is initialized as: a[5]={10,20,30,40,50};
If the size of integer is 2 a[0] a[1] a[2] a[3] a[4] संकलन के दौरान, चर a के लिए
bytes, 10 bytes will be al- 10 20 30 40 50 कं पाइलर द्वारा 5 सन्निहित मेमोरी
located for the variable a. 1000 1002 1004 1006 1008 स्थान आरक्षित किए जाते हैं और इन
Ex: consider character ini-
tialization सभी स्थानों को प्रारंभिक मान दिया जाता है। सरणी a को इस प्रकार
char b[8] = {“C”,“O”, “M”, “P”, “U”, “T”, “E”,
“R”};
प्रारंभ किया गया है:
b[0] b[1] b[2] b[3] b[4] b[5] b[6] b[7] यदि पूर्णांक का आकार
The array
b is initialized C O M P U T E R
2 बाइट्स है, तो चर a
as: 7 bytes 1000 1001 1002 1003 1004 1005 1006 1007
के लिए 10 बाइट्स
will be alloc-
आवंटित किए जाएंगे।
ated for the variable b.
2. Partial Array Initialization: partial array ini- उदाहरण: वर्ण प्रारंभिककरण
tialization is possible in C language. If the num- char b[8] = {"C", "O", "M", "P", "U", "T", "E", "R"};
ber of values to be initialized is less than the सरणी b को इस प्रकार प्रारंभ किया गया है: चर b के लिए 7 बाइट्स
size of the array, then the elements are initial-
ized in the order from 0th location. The remain- आवंटित किए जाएंगे।
ing locations will be initialized to zero automat- b. आंशिक सरणी प्रारंभिककरण: सी भाषा में आंशिक सरणी प्रारंभ
ically. संभव है। यदि प्रारंभ किए जाने वाले मानों की संख्या सरणी के
Ex : Consider the partial initialization
int a[5]={10,15}; आकार से कम है, तो तत्वों को 0 वें स्थान से क्रम में प्रारंभ किया
31
जाता है। शेष स्थानों को स्वचालित रूप से शून्य पर प्रारंभ किया Reading out data from an
जाएगा। उदाहरण :आंशिक प्रारंभिकीकरण array
The elements of an array can Code:
int a[5]={10,15}; be read and display by using
for (int i=0; i<20; i++)
भले ही कं पाइलर 5 मेमोरी स्थानों को आवंटित करता है, इस any loop.
{
घोषणा कथन का उपयोग करके , कं पाइलर 10 और 15 के साथ printf("%d\n",
पहले दो स्थानों को शुरू करता है, मेमोरी स्थानों का अगला सेट mydata[x]);
स्वचालित रूप से शून्य पर शुरू किया जाता है। }
3. Initialization without size:
If the size of the array is omitted, an array just c. आकार के बिना :
big enough to hold the initialization is created. यदि सरणी का आकार छोड़ दिया जाता है, तो आरंभीकरण को
Therefore, if you write − पकड़ने के लिए पर्याप्त बड़ी सरणी बनाई जाती है।
int a[]={10,20,30,40,50}; इसलिए, यदि आप लिखते हैं –
You will create exactly the same array as you
int a[]={10,20,30,40,50};
did in the previous example.
आप बिल्कु ल वही सरणी बनाएंगे जो आपने पिछले उदाहरण में किया था।
Runtime Array initialization
An array can also be
Code Example:
initialized at runtime
using scanf() function. int arr[4];
This approach is usu- int i, j;
ally used for initializing printf("Enter array element");
large array, or to initial- for(i=0;i<4;i++)
ize array with user spe- {
cified values. scanf("%d",&arr[i]); //Run time array initialization
}
Accessing the ele- for(j=0;j<4;j++)
ments of an array {
The elements of an ar-
ray can be accessed by printf("%d\n",arr[j]);
indices/index. Array }
subscript (or index) getch();
can be used to access
any element stored in
array. Subscript starts
with 0, which means array_name[0] would be used
to access first element in an array. In general
array_name[n-1] can be used to access nth element
of an array, where n is any integer number.

Note:
 Arrays have 0 as the first index not 1.
 If the size of an array is n, to access the last ele-
ment, (n-1) index is used.

Input data into ar-


ray Code:
The elements of an for (x=0; x<=19;x++)
array can be input {
using scanf function printf("enter the integer number %d\n", x);
in any loop.
scanf("%d", &num[x]);
}
32
An array of an array is said to be 2 dimen-
रनटाइम सरणी प्रारंभ sional array, which stores data in column and
एक सरणी को स्कै न() फ़ं क्शन का उपयोग करके रनटाइम पर भी शुरू row form.
Example: int ar[4][5];
किया जा सकता है। यह दृष्टिकोण आमतौर पर बड़ी सरणी को प्रारंभ This above array is called two dimensional ar-
करने के लिए, या उपयोगकर्ता निर्दिष्ट मानों के साथ सरणी प्रारंभ करने ray because it will store all the elements in
के लिए उपयोग किया जाता है। column and in row form.
NOTE: In above example of two dimensional array,
सरणी के तत्वों तक पहुँचना we have 4 rows and 5 columns.
सरणी के तत्वों को सूचकांक द्वारा एक्सेस किया जा सकता है। सरणी में 3) Multi Dimensional Array.
This array does not exist in c and c++.
संग्रहीत किसी भी तत्व तक पहुंचने के लिए सरणी सबस्क्रिप्ट (या इंडेक्स)
का उपयोग किया जा सकता है। सबस्क्रिप्ट 0 से शुरू होता है, जिसका अर्थ Dynamic Array.
This type of array also does not exist in c and c++.
है array_name[0] का उपयोग सरणी में पहले तत्व तक पहुंचने के लिए
किया जाएगा। सामान्य तौर पर array_name[n-1] का उपयोग सरणी के Two‐Dimensional Arrays
nth तत्व तक पहुंचने के लिए किया जा सकता है, जहां n कोई पूर्णांक The two dimensional array in C language is repres-
ented in the form of rows and columns, also known
संख्या है।
as matrix. It is also known as array of arrays or list
नोट: of arrays.
सरणी में पहले सूचकांक के रूप में 0 है, न कि 1। Declaration of two dimensional Array
data_type array_name[size1][size2];
यदि सरणी का आकार n है, तो अंतिम तत्व तक पहुंचने के लिए, (n-1) Example :
अनुक्रमणिका का उपयोग किया जाता है। int a[4][3];
Initialization of 2D Array
सरणी में डेटा इनपुट int a[3][4]={{1,2,3},{2,3,4},{3,4,5},{4,5,6}}
सरणी के तत्वों को किसी भी लूप में स्कै नफ फ़ं क्शन का उपयोग करके
इनपुट किया जा सकता है।
a[0] [0] a[0] [1] a[0] [2] a[0] [3]
सरणी से डेटा पढ़ना
सरणी के तत्वों को किसी भी लूप का a[1] [0] a[1] [1] a[1] [2] a[1] [3]

उपयोग करके पढ़ा और प्रदर्शित किया जा a[2] [0] a[2] [1] a[2] [2] a[2] [3]
सकता है।

Types of Array सरणी के प्रकार


1) Static Array 1) स्टैटिक ऐरे
2) Dynamic Array. 2) डायनामिक ऐरे

Static Array स्टैटिक ऐरे


An array with fixed size is said to be a static array. निश्चित आकार के साथ एक सरणी को एक स्टैटिक सरणी कहा जाता है।
Types of static array: स्थैतिक सरणी के प्रकार:
a. One Dimensional Array
b. Two Dimensional Array.
a. एक आयामी सरणी
c. Multi-Dimensional Array. b. दो आयामी सरणी
1) One Dimensional Array c. बहु-आयामी सरणी
An Array of elements is called 1 dimensional, 1) एक आयामी सरणी
which stores data in column or row form. तत्वों की एक सरणी को एक आयामी कहा जाता है, जो डेटा को
Example: int ar[5]; कॉलम या पंक्ति रूप में संग्रहीत करता है।
This above array is called one dimensional ar-
ray because it will store all the elements in
उदाहरण: int ar[5]; इस सरणी को एक आयामी सरणी कहा
column or in row form. जाता है क्योंकि यह सभी तत्वों को कॉलम या पंक्ति रूप में संग्रहीत
2) Two Dimensional Array. करेगा।
33
2) दो आयामी सरणी.
सरणीयों की एक सरणी को दो आयामी सरणी कहा जाता है, जो
डेटा को कॉलम और पंक्ति रूप में संग्रहीत करता है।
उदाहरण: int ar[4][5]; इस सरणी को दो आयामी सरणी कहा
जाता है क्योंकि यह सभी तत्वों को कॉलम और पंक्ति रूप में STRINGS:
संग्रहीत करेगा। String is an array of characters that is terminated
नोट: दो आयामी सरणी के उपरोक्त उदाहरण में, हमारे पास 4 पंक्तियाँ by \0 (null character). This null character indicates
और 5 स्तंभ हैं। the end of the string. Strings are always enclosed by
double quotes (“”). Whereas, character is enclosed
3) बहु आयामी सरणी by single quotes.
यह सरणी c और c++ में मौजूद नहीं है। i. In “C” language the group of characters, di-
gits, and symbols enclosed within double
डायनामिक ऐरे quotation (“”) marks are called as string oth-
इस प्रकार की सरणी भी सी और सी ++ में मौजूद नहीं है। erwise a string is an array of characters and
दो-आयामी सरणी terminated by NULL character which is de-
सी भाषा में दो आयामी सरणी को पंक्तियों और स्तंभों के रूप में दर्शाया noted by the escape sequence “\0”.
जाता है, जिसे मैट्रिक्स के रूप में भी जाना जाता है। इसे सरणी की सरणी Declaration of String: C does not support string as
या सरणियों की सूची के रूप में भी जाना जाता है। a data type. However, it allows us to represent
दो आयामी सरणी की घोषणा strings as character arrays. In C, a string variable is
data_type array_name[आकार 1][आकार 2]; any valid C variable name and it is always declared
उदाहरण: int a[3][4]; as an array of characters. The general form of de-
claration of a string variable is:
2D सरणी का प्रारंभ Syntax: char string_name [size];
Int a[3][4]={{1,2,3},{2,3,4},{3,4,5},{4,5,6}} The size determines the number of characters in the
string name.
Note: In declaration of string size must be required
to mention otherwise it gives an error.
Ex:
char str[2]={'5','+','A','B'}; // Invalid

Different ways of initialization:


i. Initializing locations character by character.
ii. Partial array initialization.
iii. Initialization without size.
iv. Array initialization with a string.

Accessing Two-Dimensional Array Elements दो-आयामी सरणी तत्वों तक पहुंचना


An element in a two-dimensional array is accessed by दो-आयामी सरणी में एक तत्व को सबस्क्रिप्ट का उपयोग करके एक्सेस
using the subscripts, i.e., row index and column index
of the array. किया जाता है, यानी, सरणी की पंक्ति अनुक्रमणिका और स्तंभ
अनुक्रमणिका।
Code:
int i=0,j=0;
int arr[4][3]={{1,2,3},{2,3,4},{3,4,5},{4,5,6}};
clrscr();
//traversing 2D array
for(i=0;i<4;i++)
{ for(j=0;j<3;j++)
{
printf("arr[%d] [%d] = %d \n",i,j,arr[i][j]);
}//end of j
34
}//end of i
getch();
The compiler allocates 10 bytes for the variable
a ranging from 0 to 9 and initializes first four
locations with the ASCII characters of “R”,
“A”, “M”, “A”. The remaining locations are
automatically filled with b[0] b[1] b[2] b
स्ट्रिंग्स: NULL characters (i.e,\0).
स्ट्रिंग वर्णों की एक सरणी है जो \0 (शून्य वर्ण) द्वारा समाप्त होती है। 3. Initialization without R A M
यह शून्य वर्ण स्ट्रिंग के अंत को इंगित करता है। स्ट्रिंग्स हमेशा डबल size : consider the de-
कोट्स ("") से घिरे होते हैं। जबकि, चरित्र एकल उद्धरणों से घिरा claration along with the initialization
char b[]={“C”, “O”, “M”, “P”, “U”, “T”, “E”,
हुआ है। “R”};
"सी" भाषा में दोहरे उद्धरण ("") चिह्नों के भीतर संलग्न वर्णों, अंकों In this declaration, the compiler will set the
और प्रतीकों के समूह को स्ट्रिंग कहा जाता है अन्यथा एक स्ट्रिंग वर्णों array size to the total number of initial values i.e
की एक सरणी है और शून्य वर्ण द्वारा समाप्त होती है जिसे एस्के प 8. The character will be stored in these memory
locations in the order specified.
अनुक्रम "\0" द्वारा निरूपित किया जाता है।
4. Array Initialization with a String: consider
the declaration with string initialization.
स्ट्रिंग की घोषणा: C डेटा प्रकार के रूप में स्ट्रिंग का समर्थन नहीं char b[ ] = “COMPUTER”;
करता है। हालांकि, यह हमें स्ट्रिंग्स को चरित्र सरणियों के रूप में Here, the string length is 8 bytes. But, string
प्रतिनिधित्व करने की अनुमति देता है। सी में, एक स्ट्रिंग चर कोई भी size is 9 bytes. So the compiler reserves 8+1
memory locations and these locations are initial-
वैध सी चर नाम है और इसे हमेशा वर्णों की एक सरणी के रूप में
ized with the characters in the order specified.
घोषित किया जाता है। स्ट्रिंग चर की घोषणा का सामान्य रूप है: The string is terminated by \0 by the compiler.
सिंटैक्स: char string_name [आकार]; The string “COMPUTER” contain 8 characters,
आकार स्ट्रिंग नाम में वर्णों की संख्या निर्धारित करता है। because it is a string. It always ends with null
नोट: स्ट्रिंग आकार की घोषणा में उल्लेख करना आवश्यक होना character. So, the array is 9 bytes (i.e string
length+1 byte for null character).
चाहिए अन्यथा यह एक त्रुटि देता है।
उदाहरण: char str[2]={'5','+', 'A','B'}; //अमान्य Reading and Writing Strings
The “%s” control string can be used in scanf() state-
प्रारंभ करने के विभिन्न तरीके : ment to read a string from the terminal and the same
i. एक एक अक्षर से स्थानों को प्रारंभिक मान देना । may be used to write string to the terminal in
ii. आंशिक सरणी आबंटन । printf() statement.
Example : char name[10];
iii. आकार के बिना आबंटन । scanf(“%s”,name);
iv. स्ट्रिंग के साथ सरणी आबंटन । printf(“%s”,name);

1. Initializing locations character by character 1. एक एक अक्षर से स्थानों को प्रारंभिक मान देना:


Consider the following declaration with initial- प्रारंभिक मान के लिये निम्नलिखित घोषणा देखें,
ization, char b[9]={“C”, “O”, “M”, “P”, “U”, “T”, “E”, “R”};
char b[9]={“C”, “O”, “M”, “P”, “U”, “T”, “E”,
कं पाइलर 0 से 8 तक के 9 मेमोरी स्थानों को आवंटित करता है
“R”};
The compiler allocates 9 memory locations ran- और इन स्थानों को निर्दिष्ट क्रम में वर्णों के साथ शुरू किया जाता है।
ging from 0 to 8 and these locations are initial- शेष स्थान स्वचालित रूप से शून्य वर्णों के लिए आवंटित किए जाते
ized with the characters in the order spe- b[0] b[1] b[2] b[3] b[4] b[5] b[6] b[7] b[8]
cified. The remaining locations are auto- C O M P U T E R \0
matically initialized to null characters.
2. Partial Array Initialization: If the characters
to be initialized is less than the size of the array, हैं।
then the characters are stored sequentially from 2. आंशिक सरणी आबंटन: यदि आवंटित किए जाने वाले वर्ण
left to right. The remaining locations will be ini- सरणी के आकार से कम हैं, तो वर्णों को बाएं से दाएं क्रमिक रूप से
tialized to NULL characters automatically. संग्रहीत किया जाता है। शेष स्थानों को स्वचालित रूप से NULL
Ex: Consider the partial initialization
int a[10]={“R”, “A”, “M”, “A” };
वर्णों से आवंटित किया जाएगा।

35
उदाहरण:
कं पाइलर 0 से 9 तक के चर ‘a’ के लिए 10 बाइट्स आवंटित
करता है और "R", "A", "M", "A" वर्णों के साथ पहले चार
स्थानों को शुरू करता है। शेष स्थान स्वचालित रूप से NULL
वर्णों (यानी,\0) से भरे होते हैं।
String Input/output Functions
The strings can be read from the keyboard and can
be displayed onto the monitor using various func-
tions. The various input and output functions that
3. आकार के बिना आबंटन: char b[]={"C", "O", "M", "P", are associated with strings can be classified as:
"U", "T", "E", "R"} के साथ घोषणा पर विचार करें; इस
घोषणा में, कं पाइलर सरणी आकार को प्रारंभिक मानों की कु ल
संख्या यानी 8 पर सेट करेगा। वर्ण निर्दिष्ट क्रम में इन स्मृति स्थानों में
संग्रहीत किया जाएगा।

4. स्ट्रिंग के साथ सरणी आबंटन : स्ट्रिंग आबंटन के साथ घोषणा


पर विचार करें। char b[] = "computer"; यहां, स्ट्रिंग लंबाई 8
बाइट्स है। लेकिन, स्ट्रिंग आकार 9 बाइट्स है। इसलिए कं पाइलर 8
+ 1 मेमोरी स्थान आरक्षित करता है और इन स्थानों को निर्दिष्ट क्रम
में वर्णों के साथ शुरू किया जाता है। स्ट्रिंग कं पाइलर द्वारा \0 से Unformated I/O Functions
समाप्त हो जाती है। स्ट्रिंग " computer " में 8 वर्ण हैं, क्योंकि यह
एक स्ट्रिंग है। यह हमेशा शून्य अक्षर के साथ समाप्त होता है। तो, 1. getchar() function : A single character can be
सरणी 9 बाइट्स है (यानी शून्य वर्ण के लिए स्ट्रिंग लंबाई + 1 given to the computer using “C” input library
function getchar().
बाइट)। Syntax : char variable=getchar();
The getchar() function is written in standard I/O
स्ट्रिंग्स को इनपुट लेना और आउटपुट देना library. It reads a single character from a stand-
"%s" नियंत्रण स्ट्रिंग का उपयोग टर्मिनल से एक स्ट्रिंग को पढ़ने के ard input device. This function do not require
any arguments.
लिए scanf() कथन में किया जा सकता है और इसका उपयोग
2. putchar() function :The putchar() function is
printf() कथन में टर्मिनल को स्ट्रिंग लिखने के लिए किया जा सकता used to display one character at a time on the
है। standard output device. This function does the
उदाहरण: char name[10]; reverse operation of the single character input
scanf ("%s", name); function.
Syntax : putchar(character variable);
printf ("%s", name);

Code Example1:
char ch[13]={'c', 'p', 'r', 'o', 'g', 'r', 'a', 'm', 'm', i', „n‟, „g‟, „\0‟};
char ch2[13]="cprogramming";
printf("Char Array Value is: %s\n", ch);
printf("String Literal Value is: %s\n", ch2);
Output
Char Array Value is: cprogramming
String Literal Value is: cprogramming

Code Example2:
char name[20];
printf("Enter name: ");
scanf("%s", name);
printf("Your name is %s.", name); 36
Output
Syntax : puts(char type of array variable);

Code for Program using gets() fun


puts("Enter String name:");
gets(str);
स्ट्रिंग इनपुट / आउटपुट फ़ं क्शंस
puts("Print the string name:");
स्ट्रिंग्स को कीबोर्ड से पढ़ा जा सकता है और विभिन्न फ़ं क्शंस का
puts(str);
उपयोग करके मॉनिटर पर प्रदर्शित किया जा सकता है। स्ट्रिंग्स से जुड़े
विभिन्न इनपुट और आउटपुट फ़ं क्शंस को इस प्रकार वर्गीकृ त किया जा
सकता है: 5. getc(): This function is used to accept a single
character from the standared input to a character
variable.
Syntax : character variable=getc();

6. putc():This function is used to display a single


character in a character variable to standared out-
put device.
Syntax : putc(character variable);

7. getch():The getch function reads a single character


directly from the keyboard, without echoing to the
screen.
अनफॉर्मेटेड इनपुट/आउटपुट फ़ं क्शंस
8. getche():The getche() function reads a single char-
1. getchar() फ़ं क्शन: "सी" इनपुट लाइब्रेरी फ़ं क्शन getchar() acter from the keyboard and echoes it to the current
का उपयोग करके कं प्यूटर को एक एकल वर्ण दिया जा सकता है। text window.
सिंटैक्स: char variable = getchar();
String Manipulation Functions/ String
getchar() फ़ं क्शन मानक I / O लाइब्रेरी में लिखा गया है। यह
Handling Functions
एक मानक इनपुट डिवाइस से एकल वर्ण पढ़ता है। इस फ़ं क्शन को The various string handling functions that are suppor-
किसी भी आर्गुमेन्ट की आवश्यकता नहीं है। ted in C language are as shown:
2. putchar() फ़ं क्शन: putchar() फ़ं क्शन का उपयोग मानक
आउटपुट डिवाइस पर एक समय में एक वर्ण प्रदर्शित करने के
लिए किया जाता है। यह फ़ं क्शन एकल वर्ण इनपुट फ़ं क्शन का
रिवर्स ऑपरेशन करता है।
सिंटैक्स: putchar(character variable);

String Function Description विवरण


strlen(str) Returns the length of the string str. स्ट्रिंग str की लंबाई देता है।
3. strcpy(str1,str2) Copies the string str2 to string str1 स्ट्रिंग str2 को स्ट्रिंग str1 में कॉपी करता है
strcat(str1,str2) Append string str2 to string str1. स्ट्रिंग str2 को स्ट्रिंग str1 में जोड़ता है
All
strlwr(str) Converts the string str to lowercase स्ट्रिंग str को लोअरके स में कनवर्ट करता है
strupr(str) Converts the string str to uppercase. स्ट्रिंग str को अपरके स में कनवर्ट करता है।
strrev(str) Reverse the string str. स्ट्रिंग str को रिवर्स करता है।
strcmp(str1,str2) Compare two strings str1 and str2. दो स्ट्रिंग्स str1 और str2 की तुलना करें।
gets() : The gets() function is used to read the string these functions are defined in string.h header file.
(String is a group of characters) from the standard 1. strlen (string) – String Length : This function is
input device (keyboard). used to count and return the number of charac-
Syntax : gets(char type of array variable); ters present in a string.
Syntax: var=strlen (string);
4. puts() :The puts() function is used to display the
string to the standard output device (Monitor).

37
3 gets() : gets() फ़ं क्शन का उपयोग मानक इनपुट डिवाइस 2. strcpy(string1,string2) – String Copy : This
(कीबोर्ड) से स्ट्रिंग (स्ट्रिंग वर्णों का एक समूह है) को पढ़ने के लिए function is used to copy the contents of one string
to another string.
किया जाता है। सिंटैक्स: gets(सरणी का नाम ); Syntax: strcpy (string1, string2);
4 puts(): puts() फ़ं क्शन का उपयोग स्ट्रिंग को मानक आउटपुट Where, string1: is the destination string.
डिवाइस (मॉनिटर) पर प्रदर्शित करने के लिए किया जाता है। string 2: is the source string.
सिंटैक्स: puts(character variable); i.e the contents of string2 is assigned to the con-
tents of string1.

3. strlwr (string) – String LowerCase : This func-


tion is used to converts upper case letters of the
string into lower case letters.
Syntax: strlwr (string);

4. strupr (string) – String UpperCase : This func-


tion is used to converts lower case letters of the
string in to upper case letters.
5 getc(): इस फ़ं क्शन का उपयोग स्टैंडर्ड इनपुट से एक वर्ण चर में Syntax: strupr (string);
एकल वर्ण को स्वीकार करने के लिए किया जाता है।
5. strcmp(string1,string2) – String Comparision :
सिंटैक्स: character variable = getc();
This function is used to compares two strings to
find out whether they are same or different. If
6 putc(): इस फ़ं क्शन का उपयोग वर्ण चर में एकल वर्ण को स्टैंडरेड two strings are compared character by character
आउटपुट डिवाइस में प्रदर्शित करने के लिए किया जाता है। until the end of one of the string is reached. If
सिंटैक्स: putc)character variable); the two strings are same strcmp() returns a value
zero. If they are not equal, it returns the numeric
7 getch(): getch फ़ं क्शन स्क्रीन पर गूंजने के बिना, सीधे कीबोर्ड से difference between the first non-matching char-
acters.
एक एकल वर्ण पढ़ता है।
Syntax: strcmp(string1,string2);

8 getche(): getche() फ़ं क्शन कीबोर्ड से एक एकल वर्ण पढ़ता है


और इसे वर्तमान टेक्स्ट विंडो में प्रतिध्वनित करता है। Code Example:
1. char name[]="JBREC";
int len1,len2;
स्ट्रिंग मैनिपुलेशन फ़ं क्शंस/ स्ट्रिंग हैंडलिंग फ़ं क्शंस clrscr();
C भाषा में समर्थित विभिन्न स्ट्रिंग हैंडलिंग फ़ं क्शन निम्नानुसार हैं: len1=strlen(name);
len2=strlen("JBRECECE");
printf("The string length of %s is: %d\n",nam
printf("The string length of %s is: %d","JBRE

2. char str1[]="REDDY";
char str2[10];
strcpy(str2,str1);
printf("The string1 is :%s\n",str1);
printf("The string2 is :%s\n",str2);
strcpy(str2,str1+1);
ये सभी फ़ं क्शंस string.h हेडर फ़ाइल में परिभाषित किए गए हैं। printf("The string1 is :%s\n",str1);
printf("The string2 is :%s",str2);
1. strlen (स्ट्रिंग) - स्ट्रिंग लंबाई: इस फ़ं क्शन का उपयोग स्ट्रिंग में 3. char str[]="JBREC";
मौजूद वर्णों की संख्या को गिनने और वापस करने के लिए किया strlwr(str);
जाता है। सिंटैक्स: var=strlen (स्ट्रिंग); printf("The lowercase is :%s\n",str);

38
2. strcpy(string1,string2) - स्ट्रिंग कॉपी: इस फ़ं क्शन का
उपयोग एक स्ट्रिंग की सामग्री को दूसरे स्ट्रिंग में कॉपी करने के
लिए किया जाता है। 4. char str[]="jbrec";
सिंटैक्स: strcpy(स्ट्रिंग 1, स्ट्रिंग 2); strupr(str);
यहाँ, स्ट्रिंग 1: गंतव्य स्ट्रिंग है। स्ट्रिंग 2: स्रोत स्ट्रिंग है। यानी printf("UpperCase is :%s\n",str);
स्ट्रिंग 2 की सामग्री स्ट्रिंग 1 की सामग्री को सौंपी गई है। 5. char str1[]="reddy";
char str2[]="reddy";
3. strlwr (स्ट्रिंग) – स्ट्रिंग लोअरके स: इस फ़ं क्शन का उपयोग int i,j,k;
स्ट्रिंग के ऊपरी के स अक्षरों को निचले के स अक्षरों में i=strcmp(str1,str2);
परिवर्तित करने के लिए किया जाता है। j=strcmp(str1,"subba");
सिंटैक्स: strlwr (स्ट्रिंग); k=strcmp(str2,"Subba");
printf("%5d%5d%5d\n",i,j,k);
4. strupr(स्ट्रिंग) – स्ट्रिंग अपरके स: इस फ़ं क्शन का उपयोग
स्ट्रिंग के निचले के स अक्षरों को ऊपरी के स अक्षरों में
परिवर्तित करने के लिए किया जाता है। 6. strcat(string1,string2) – String Concatenation:
This function is used to concatenate or combine,
सिंटैक्स: strupr (स्ट्रिंग); two strings together and forms a new concaten-
ated string.
5. strcmp (string1,string2) - स्ट्रिंग तुलना: इस फ़ं क्शन Syntax: strcat(sting1,string2);
का उपयोग दो स्ट्रिंग्स की तुलना करने के लिए किया जाता है Where, string1: is the first string1.
string2: is the second string2
ताकि यह पता लगाया जा सके कि वे समान हैं या अलग हैं।
When the above function is executed, string2 is
यदि दो स्ट्रिंग की तुलना वर्ण द्वारा की जाती है जब तक कि combined with string1 and it removes the null
स्ट्रिंग में से एक के अंत तक नहीं पहुंच जाता। यदि दो स्ट्रिंग character (\0) of string1 and places string2 from
समान हैं, तो strcmp() एक मान शून्य देता है। यदि वे समान there.
नहीं हैं, तो यह पहले गैर-मिलान वर्णों के बीच संख्यात्मक 7. strrev(string) - String Reverse :This function is
used to reverse a string. This function takes only
अंतर लौटाता है। one argument and return one argument.
Syntax: strrev(string);

6. char str1[10]="jbrec";
char str2[]="ece";
strcat(str1,str2);
printf("%s\n",str1);
printf("%s\n",str2);

7. char str[20]; O
printf("Enter the string:");
scanf("%s",str);
printf("The string reversed is:%s",strrev(str

OUTPUT: The lowercase is: jbrec

39
6. strcat (string1,string2) - स्ट्रिंग कॉन्के टेनेशन: इस फ़ं क्शन
का उपयोग दो स्ट्रिंग को एक साथ जोड़ने या संयोजित करने के लिए
किया जाता है और एक नया शंकु बद्ध स्ट्रिंग बनाता है।
सिंटैक्स: strcat (sting1,string2);
यहाँ, स्ट्रिंग 1: पहला स्ट्रिंग है। स्ट्रिंग 2: दूसरा स्ट्रिंग है
जब उपरोक्त फ़ं क्शन निष्पादित किया जाता है, तो स्ट्रिंग 2 को स्ट्रिंग
1 के साथ जोड़ा जाता है और यह स्ट्रिंग 1 के शून्य वर्ण (\0) को
हटा देता है और स्ट्रिंग 2 को वहां से रखता है।

7. strrev(स्ट्रिंग) - स्ट्रिंग रिवर्स : इस फ़ं क्शन का उपयोग स्ट्रिंग को


रिवर्स करने के लिए किया जाता है। यह फ़ं क्शन के वल एक
आर्गुमेन्ट लेता है और एक आर्गुमेन्ट वापस करता है।
सिंटैक्स: strrev(स्ट्रिंग);

40

You might also like