0 ratings0% found this document useful (0 votes) 70 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 peocedural
fey met
iS y uoas nitially evelopect by Dennis Ritchie tw the years
at the Bel Telephone Laboratories to develop the UNIX
eet system
Gs 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 , divers, 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
weather wecasling ete.
Clc++ code ts very faster than a code toritten in
qava Python. . Z
ME C tokens ave the basic balding blocks th ¢ Aang
C token ave the smallest — thdividuals unit.
© Keytoosds © Tdentigiers ~ © Constants
@ Operators @ Special SymbolsCheysord ) ter
used in Programming that have special meanings to compiler:
(nt money; Herve, int ts keyword and money is vartable-
Keywords are P i le
These ave keywords tn C Lan;
Mr
Such as vaviables, functions , structures ete.
Tdentifiess must be Unique, as they axe created to give a
unique name to an entity to identify Bing the execution
program.
Whores names must pe ED, vom keywords.
@& int money ; Hese money 4 acourtbalance are Wenti-
double accountbalance ; Hers.
(Constants) WEF A constant is a value that car'ibe changed
the prayram.
— 10, 20, 4S0 ete.
> '@.'b? ete, Octal constant - 021,033, 016 ete
opevator ts simply a symbol that is
S
There can be many types Of operations dike arithmetic
gamle
Avithmetic Opesators [+,-, ¥, / ]
Relational Operators [< <=, > >=, =5,
ico ators [ee . il, } Jum
In Programming danguage, the special
Symbols have some special meantig and they con not
be used for other purposes.
GP 0,1 tL, ote
te]
{ €xclamation mark — Underscove = Colon
% Number sign + plus sign * semicolon
ele Pewcent sign > comma Quotation mask
Ampersand / slash ? Question mark
* Asterisk Equal. to sign * Period.iWarc program basically Consists (Héllostdorla. program
Of the following pasts - #f include
© Preprocessox Commands int mainds i ai
® Functions [*Ptyst program */
© variables prinlf(" Hello , Klorld [\n"};~~
® Statements 4 Expressions return 05 $ ae
® Comments l
det us take a Look at the various paris of the above
‘Hello , World!" Program —
The first Line of the program Hindude is a
pre-processoy command which tells a ¢ Compiler to (nelude
gtdio-h file before going te actual comptlation-
The next line int mainc) ts the main function wh-
-eve the program execution begins.
WG Te next Line /*------ *[ wlll be ignored by the comp-
-tler, so such ALfves ase called comments in the program
EGF The next Line printfG--) ts another function ushich
causes the message “Mello, World!’ to be displayed on scxeen.
W& Te next Line veturno; terminates the matn function &
returns the value 0.
© dato types vefers to On extensive system usec for dedoxive +
ov {UMMM = of different types.
S Tre type of a variable determines hous much space lt ocu-
“pees ln Storage.
we Different lata types have different vanges to steve nos.
W& Pasically data types ave of cliffesent types —
i
© Derived Data Type (Pointers . Arrays » structures » Union )Speifiers
ed
siefined tri: 6 Jorquage. | 4) int
Primary data typestn C es =128 to 127 8 |
se of MY types + tnt , chav, oa oe ahs
: st dlouble- [4 |double 2:3€-308to 16 +309, 1 OF
i the int sata type is used
to cers integer values. Re
ir can be signed ov un signed signed tnt-
+ thas petal 32 bils (4 bytes). unsigned int-
signed.
The chas data type ts used to
Lnibblee Ubits
stese the chavacterc~
W& chasacters must be ingide single quotes:
ién usually 4 byle- Range: ree)
Whenever we entey a characler type variable, the chara-
~cles is sloved as tnleges value tn the Address Location
¢ float clata type ts used to
e oatin point numbers:
The numbers that have a fractional past are called
oating point numbers- Range:
ei has generally 4 bytes +
These can vepresent = me dager and wilder vonge of
digits as compared! to tn data types
UBLE | T =k The double dota type is used
to stove floating numbers .
Tt occupies twice as much memory as float data type.
tt has genesally a bytes % Range: 23
int - 19 20, 30, 100, 1000, 586 ae
char - a4 ‘pl, 'L', tw "se Rot a
float - 0.7, 0.33 , G21, 6-43, (000.29, 562.0) ete.
double — 32.334000 , 14u.469B300 — eteta Ty ce Enumeration Cenum ) ts
a user defined data type- CBD \ Cnuvn datatype
Tt is mainly used to assign | # include
names to Lntegral constants int maint) £
Value Assignee! must be tn range ehum etter Fab, dP}
Of signed tnt. enum deter g: dy
Syntaxs) enum enumnamet — 4; | printf ("id 7 y); Pea
enum enumname + setund; 3 i
Specifies whether to Inlespret the Coxsesponding argument as a
Chasacter . a sting, a pointes, an tnteger or 9 number.
ee ; :
Heled| signed int It ld | tong tnt |b | Potter
hu unsigned int — “hd | dong Long tnt +s String
bhi shlu | Unsignedl long int “I. X | Hexa decimal
hu “Flite nsignes Long Leng int ko eeta. Integer
aS A variable (5 @ name given to Storage area
that ous programs Can manipulate. RB riasranees
UB Too main Concepts of variable; void mainl)
@ Declaration int a;
© Initialization & Usage Q= 10,
Nastable name starts with owes
cose ox underscoxe (_)-.
B® int abad: + declasing multiple variables tn single line
(nt azsi int bz5;—> declaying 2 tnilializing variables.
j= A constant” is a value Tat can’t be
to to 5, value ts
Q=5; FAvaried, solt ts
changed tn the program- @ Chov > ‘#',, Qik OES les
BS Gypes chor, staing integer| ‘abe’ > X lot a chor
eal valued » St SS ai empty can't be
@ String> "GATE", Book", thar
“India is my County" | % —> X Not valid. must
“Newton Desk ” be Im single quotes:ES an opevatos is a symbol that tells the compiler te_perform
specifte mathematic
TIC OPERA
SZLZZIEITIT TTT
Seca OE. |
1
+ Adlde tion operands. 4
| ___Subtracts second sperand gromfirst:.
* _ 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 = scill
ement operator clecreases
the Cnteges value by one: |
Checks if the values of two operands
ame equal or not. Cf ves then the
Condition becomes trie,
lc | Cheeks tt the values of troo operands
| 1= | eve equat or net. I} Ale, then the.
Condition becomes true-
i TH e of wunch és Grea-
> er Bran nee of ig oped
| The value of let opesand is
LS | Us than the value of right operand.
“The value of Le$t opesancl Ls greates
than or equal to the value of |
Me Lrignt operand: |
than or equal t the value ot
ft
le ~ value of dept operand is lese
|
| right operand:
or _dogital functions.
int mained §
int a=n ,be4;
print? ("Sum = eecl\n”, a+b);
peintt CL" Diff 2 d\n", a-b);
print (" Quotient = “d\n”, ala);
pent ( Remainder= 7d \n", arleb)
printf Ci asvd\n" ++);
yetusn 0;
int matnu) §
int a=12, b= 4;
iy dSgreatnttanns/-o \n's Qk);
printé (tieel is equal te-Ad \n"a,b);
i#laj=b)
printé Ud ts not equat to
ed \n? a,b);
welurn o;
la>b
printf
tla.Ops. Descesfption
Logical: Anns Lf both the
4d | operands are non Zero then |
Condttions becomes true. i
| Loptead ot > any of 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 circuit incase of £2 >
NU there ts a condition
|@rywohere tr e& pression that —
return false then yest of the
Cond” after that will not evaluatec|
er fn expression that yetusy
fue then rest ofthe condition,
46 operand. after that will not be evaluates
aaa, ~ ~ a . =
BITWISE OPERATORS I) Lee (aor Tasce z
Samay eae ene PAG
Ops 5
oa Raa ate al o o °
g Btnacy AND-> Tt copies a bt f 8 7
to the result Y Ut exib fn 0-| ° J dt
cMeslloaa a | \
Binasy OR» Lt coples a Bt YY ; \
|| exists tn efther operands. | i. 2
1). | Binaxy xoR—> Tt copies the bit
Une) : | oTn bitise Left/Right shyp
shell ceae ie AE. sper the trailing andl tebatng
eS Binary One's complement» Tt hag Pos? are ‘Hued tot, 20x06,
the ctect of Sipping bits.
ie “|Binasy Left shift > The value. ts
es movecl Lett by the. numberof
Descziption
4 peal bicsd pitas pemavid 3] Right shifting is equ
iy | Bling Aigne pee te asge Tae ae
>»> operablal ga eukS area aight by ee dvlon 4 ae
ie the no of bits specified. BAG Opes
Assignment op’ > Assigns valu — p?
right Bie
Ss sai xia’ to left operand. Bend
[Subtract ahet asci pent opt» | and assignment
-= (Lt cubstracte Se vigt oper rip ga
jand. assign t kept operands |, operand & assign to lefet_ Divide ancl Assignment opfs|| Modulus and Assignment opt
'= Tt olivicles the Gee operand) ¥j,-| Tt takes modulus using too
with the right operand 4 operands £ assigns the result
pessigns: ope pat Lge ara
Left shift and assignment op >>= Right shift ancl assignment opt: |
Bitwise and assignment: opr. n= | Bitwise ex-oR & assignment opr:
Bitwoise oR L ascignment opt "
) Returns the of variabl
Returns the address of vasiable-
| Pointer to a varfable-
Sizeof OPERATOR [see OF ae PWG sock, operator com-
~putes the size of variable Coyte)-
aS x ts a unasy operator.
For float values use dike this Le io2F otheswise ft wtll be
treatec! as doubleCio2) oF use typecasting for float and cloubk-
BES for chasactes data type ie char values” use typecacting or
dfrectly use datatype ox variable-
Operands can be variable , constant data pe:
size of (x); , sizeof lint); , sizeof ts);
(vee casteng Jy /ge Tt refers to changing an
variable of one dala type tnto another.
BS me compiles uatll automatlealty change one type of data nto
another [tf [tt make sense.
af Types “EMPureeT TYPE reXPLECET ~ TYPE”
@hWhen the type conversion is perfor-[ ® The type conversion performed
-med automal ically by the compiler by the programmes by posing the
wofthout programmer's intervention cata. type of expression of speefHe
Sud) type of Lonversion is kneon type ts known as explicit type
as implicit type eonversion or type 7 _eonversion-
romotion.s
tnt x;
for (X=491; x<=122; x44)
intx;
get For (1291; xee 125 X44)
ies
re Svinte Une", (hav) x);
we
\ t
tostnte Coc! x);
j
You might also like
Getting Input From Input Dialog Boxes: - Byte, Short, Int, Long, Float, Double, Char, Boolean
Getting Input From Input Dialog Boxes: - Byte, Short, Int, Long, Float, Double, Char, Boolean
59 pages