0 ratings0% found this document useful (0 votes) 69 views8 pagesC Programming and Data Structures Notes Sample Compressed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
if C is a psoceduval penne dengue’
i 1» boas Initially evelopect by Dennis Ritchie tn the years
at the Bel Telephone Laboratories to develop the UNIX
yen systen-
G Programming is consideved as the base for the other
Paogramming danguages, that’s vohy tb ls known as mothers
language -
C language is the system — psogrammin danguage because
it can be used to do bow- devel fram :
Tt ts generally used to create hascwave devices, Operating
dystem, dvivers, Kernels ete.
The main features of the C donguage Includes dew -
devel memory access , Q simple set of Keywords & a clean style
Tt ts used in dot of scientific Computing Uke AL/ML
woeathe: secasti ete.
Clc++ code ts very faster than a code toritten in
qava Python. . ff:
ME Cc teens ave the basic buflding blocks tn ¢ Aang.
C token ave the smallest thdividuals unit.
© Keyroosds © Identifiers @ Constants
@ Operators @ Special Symbols[Keyword ee wosds axe predefined & reserve words
4 prede}
used in Programming that have special meanings to compiler:
(nt money; Herve, tnt ts keyword and money is vartable-
keywords ase auto. break, chat, Continue , default ete
These ave keywords tn C fongu e-
BO Tentigtys refers to name given to entities
Such as vaviables, functions , structures ete.
Tdentifiess must be unique . as oe axe create! to give a
unique name to an entity to identify ¢ during the execution
ete som
Tdentiffves names must be difjerevit from keywords.
@& int money 5 Hese monty 4 acountbalance are ot
double accountbalance ; 5
(Constants) WE A constant is a value that can'tbe changed
tn the program.
B® dectrmal constant -» 10, 20, 4So ete.
Chasacter constant — ‘ah? ete, Octal constant -» 021,033, 016 ete:
(Operatovs |) mG ar operator is simply a symbol that is
used to perform operations.
There can be many types Of operations Like aytthmeti,
wogtcat, bitwise etc.
Arithmetic Opesators [+,-, ¥, / ]
Relational Operators [< <=, > >=, ==, I=]
pevators [ ££ , il, } J
Tn Programming danguage, the Special
Symbols have some special meantng and they con not
used for othes purposes.
be
GPO, t. 2, ote
{ €xclamation mark — Underscove = Colon
# Number sign + plus sign * semicolon
ele Pescent sign > comma Quotation mask
Ampersand / slash ? Question mark
* pste risk Equal to sign * Period.Ware program basically Consists!
of the following pasts — # include
© Psepsocessox Commands int main) 4
® Functions [*Ptyst program */
© Variables printf(" Hello , World |\n");,
® Statements & Expressions return 0, §
® Comments
det us take a Look at the various parts of the above
‘Hello , World!" Program —
The first Line of the Program #indude (s a
pre-processov command which tells a ¢ Compiler to (nelude
gtdio-h file before going t actual comptlation-
The next line int mainc) ts the main function wh-
-eve the program execution begins.
& Tre next Une /*------ *7 wlll be ignored by the comp-
-tler, so such ALfves ase called comments in the program
BGP The next Line printfG--) ts another function ushich
causes the message “Mello, World!’ to be displayed on screen.
IG Tre next Line veturno; terminates the matn function &
returns the value 0.
aS
© data types veders to an extensive system used for decloring
vasiables ox functions af diferent types
The type of a variable determines how much space it ocu-
ues ln storage.
B& dijferent data types have different anges to steve nos.
W® Pasicatly data types ave of clifferent types —
® Primary Data Type (char, Hoat , Int )
@ User defined Data Type ( Enum , Typedef )
© Desived Data Type ( Pointers , Axvays » steuctures , Union )known as fundamental data
Ne Speifier
types because they ave pse. aa
defined in C Aanguage- i “hed
ie Psimasy data types in C Ke |
ase of 4M types + tnt , chav, bd
oat & double. 4 double of Uf
(INTE QB Tre int dato type is Used
to shore integer values. Range :
It can be Signed ot un signed Signed tnt—
+ has generally 32 bils CU bytes). Unsigned int
signed -
The chas data type ts used to
Lnibblee Ubits
stese the chavacterc~
WF chasacters must be ingide single quotes:
ifn usually 4 we pony:
Whenever we entexy a characler type variable, the chara-
~cles is stored as
eyes Value (in the Address Locattors
J a ne float data type ts used to
e€ floating point numbers.
The numbers that have a fractional past are called
oating point numbers: Range:
ar has generally 4 bytes +
These can wepresent @ much dager and wider ange of
dlgtts as compares! to integer data types
IBLE | 0 The double data type is used
to stove floating numbers .
Tt occupies twice as much memory as float data type.
Tt has genesally % bytes Range:
int - 10, 20, 30, 100, 1000, 586 ete
Stove
OHO = al scito NU", Mn at Sin, x! A NG tok Oe iets
Hoat - 0.7, 0.33 , B21, 6-43, 1000.29, 562.0! ete.
double — 32.334000 , 14u.469B300 — eteita Ty ie Enumeration Cenum ) ts
@ user defined data type- CBD \-Enuvn datatype
Tt is mainly used to assign | # include
names to {ntegral constants int maint) £
Value Ossignec! must be tn range ehum etter Fab, dP}
Of signed tnt. enum deter gy: dy
Sgntaxs! enum enumnamet 4; | printf (dT y); Pea
enum enumname + seturno; 3 i
Specifies whether to Intespret the Coxsesponding argument as a
Chasacter . a stsing, a pointes, Qn tnteger or 9 number.
ee ; :
Hcled| signed int It ld | tong tnt || eb | Potter
bu unsigned int — “hl | dong Long tnt +g String
bhi shlu | Unsigned long int “I. X | Hexa decimal
hu “Hllu nsignes Long Leng int ko cata Integer
a A variable (5 @ name given to Storage area
that ous programs Can manipulate. BB rwasanees
UF Too main Concepts of variable; void mainl)
@ declaxation int a;
© Initialization & Usage Q= lo,
Nastable name starts with owes
cose ox underscoxe (_)-.
BF int abad; + declasing multiple variables tn single line
(nt ass; int bz5;—> decaying 4 tnilializing variables.
je A constant” is a value at can’t be
to to 5, value ts
Q=5; FAvaried, sol ts
changed tn the program- @ Chev > ‘#', Qik ROME hes
BO Fires chor, sizing. integer| ‘abe’ > X alot a chav
weal valued » St SSS a tmpty can't be
@ String> “GATE”, "Book", that
“India is my County" | % —> X Not valid. must
“Newton Desk ” be In single quotesES an opevatos is a symbol that tells the compiler te_perform
specie mathematic
TIC OPERA
SEZ
ere ae |
1
| + Adlde tion operands. 4
| ___Subtracts second sperand srom#first:|
* _ Muttfplies both operands. _|
poe Divfoles numerator by de- num’
| 7° Modulus operator and xematnder
of after an integer division: |
++ Inexement operator tnereases the |
} value by ones = sill
ement operator clecreases
the [nteges value by one. |
Checks if the values of two operands
(ane equal or not. Cf ves then the.
Condition becomes trie,
lye | Cheeks tt the vatues of troo operands
| 1= | eve equat or not. I} Ale, then the.
Condition becomes true-
i TH e of wunch ts Grea- |
> er Bran nese of ig oped
| The value of let opesand is
LS | Gass than the valut of right operand:
“The value of Le$t opesancl Ls greates
than or equal to the value of |
a Lriant operand: |
than or equal t the value ot
1
le “ value of dept operand ts lese
|
| right operand:
or _dogital functions.
int mained §
int a=n ,be4;
print? ("Sum = eecl\n”, arb);
peintt C' Diff 2 d\n", a-b);
print (" Quotient = “d\n”, ala);
pelntt C Remainder= 7c \n", arleb)
paintf C'asvd\n" ++);
yetusn 0;
int matnu) §
int a=12, b= 4;
Py dSgreatnttanns/eol \n's Qk);
print? (tel is equal te-Ad \n"ab):
i$laj=b)
printé Ud ts not equat to
ed \n? a,b);
welurn 0;
la>b
printf
tela.Ops. Descexfption
Logical anins> Lt both the
4d | operands are NON Zero then |
Condttions becomes true- i
| Loptead ot > ZF any ef the
two eperands ts non Zero,
then cond* becomes true.
Logical NOT Tt ts used to
weverse the logical state of
NOTE # True rl j Falsero
Short Cireuit incase of £2 >
NU there ts a condition
|@ryohere tm e& pression that —
return false then yest of the
Cond” after that will not evaluate
er fn expression that yetusy
fue then rest ofthe condition,
48 operand. after that will not be evaluates
-0aen ~ ~ a ‘i %
BITWISE OPERATORS a) ae (aor Tasce 3
aaa Beene ene Pag
Opa: art
oa RAS ete ail o o °
g Btnacy AND-> Tt copies a bt fo 8 g
to the result ¥ Ut exib fn 0-1 ° J dt
ceslelon as ae | \
Bihasy OR» Lt coples a Bt YY , |
|| exists tn efther operands. | i. =
i). | Binaxy xoR—> Tt copies the bit
Une) : | oth bitise Left/Right shyt
shot ceae ie AS. sper the trailing anel tedatng
eS Binary One's complement» Tt hag Pos? are ‘Hued toby, zer0e
the ctect of Sipping bits.
ce “|Binasy Lept shift >The value. ts
es movecl Lett by the. numberof
Descziption
4 Heal bycrd plates peeavid 3] Right shifting is equ
[| Blniy Aight pee me aspe ae oe
>> operablal SUS area aight by ee don 4 ae
ie the no of bits specified. Blt Opes
Assignment op’ > Assigns valuu| = pt
-xight eed
Ss seat aig to left operand. Bp d
|Subtract ahel asci PrENE opt | and assianment
-= | Lt cubstracte srg oper ruil ga
jand. assign t kept operands | operand & assign to left_ Divide ancl Assignment opfs|| Modulus and Assignment opt
‘= Tt olivicles the Gee opera) ¥j,—| Tt takes modulus using too
with the sight operand 4 operands £ assigns the result
pessignis’ ope parol Le epee
Left shift and assignment op >= Right shift ancl assignment opt: |
Bitwise and assignment: opr. n= | Bitwise ex-oR & assignment opr:
Bitwoise oR L ascignmert opt S
) Retusns the of variabl
Returns the address of vasiable-
| * Pointer to a varfable-
Sizeof opERATOR [size OT ya OWE sicck, operator com-
~putes the size of variable Coyte)-
ae x ts a unasy operator.
For float values use dike this Le io2F otheswise ft utll be
treatec! as doubleCio2) oF use typecasting for float and cloubk.
BE for chasactes data type ie char values” use typecasting or
dfrectly use datatype ox variable-
Operands can be variable, constant data pe
size of (x); , sizeof lint); , sizeoPts);
Civeecasteng Jy /gle Lt refers to changing an
variable of one dala type tnto another.
BS me compiles uafll automatlealty change one type of data tnto
another (tf [tt make sense.
ag Types» ‘EMPureeT TWP reXPLECET ~ TYPE”
@hWhen the type conversion is perfor-/ ® The type conversion performed
-med automal ically by the compiler by the programmes by posing the
wolthout programmer's intervention clata. type of expression of speefHe
Sud) type of vonversion is kneaon type ts known as explictt type
as implicit type eonversion or type 7 _eonversion-
romotions
tnt x;
for (X=491; x<=122; x44)
intx;
ete For (1291; xee 1225 X44)
ies
ol Svinte Une", (hav) x);
0
\ t
Tate Coc! x);
j