Partial preview of the text
Download C Programming Fundamentals: Tokens, Data Types, Variables, Operators and Type Casting and more Study notes C programming in PDF only on Docsity!
PROGRAMM | om C is a psocedural programming danguage MS tt wns Initially developed by Derinis Ritchie th the year iti at the Bell Telephone Laboratories to develop the UNIX pee system: C programming ts tonsidleved as the base for the othes ppg aiming danguages, that’s wohy it is known as mother language « if @ dangu e ts the system Cs soa danguage because it can be used to do bow- Level scamming - Tt ts genecally used to create hasdwave devices, Operating dystem, dlsivers, kesnels ete. y ‘The main features of the C language Includes dow - devel memory Access , Q simple set of Keywords & Q clean stule It ts used in dot of scientific Computing dike AL/ML cemmenacinammegs? weather wecasling ete. iS Clctt+ code ts very faster than a code to dava , Python: ..... . ritten tn HZ, Ga TOKENS a iG C tokens ase the basic buflding blocks tn C Jang. C token ave the smallest individuals untt. ® Keywords ® Tdentifiers © Constants @ Operators @ Special Symbols Keyword BE keywords ase predetined & reserve words e predey used in Programming that have special meanings to compiler. (ER (nt money; Hese, tnt is keyword and money is variable - Keywords ase auto, break, chav, Continue , default ete. These ave keyworels in C dan uage- ie Tdentifivs wefers to name qiven to entities suth as variables, functions , structures ete Tdentifiess must be Unique, as they axe created to give a unique name to an entity to identify i during the execution oe Identifires names must be difjevent prom keywords. @@a int money ; Hee money 4 accountbalance are teat double accountbalance ; i 4 constant (s a value that (n't be Changeol tn the program. CB Declmal constant - 10, 20, USo0 ete. Chasacter constant — ‘Qh’ ete Octal constant = 021,033, o16 ete- (Operators) A ar operator is simply a symbol that is used to petfoxm operations. There can be many types of operations dike arithmetic, Wogtcal, bitwise etc. Avithmetic Opesators [+,-, ¥, / ] Relational Onexators [< 45> ,5= .== 12] dopical Operators [ £& , Il, J J es Tn programming language, the special Symbals have some Special moentiy and they con not e@ used for othes — purposes. be u Cen? E1626); 43, ees Sey + ete- { €xclamation mask — Underscore * Colon % Number sign + plus sign > semicolon “le Pescent sign > comma ” Quotation mask 2. Ampersand / slash 2 Question mark * Aste visk Equal to sign * Period. known as fundamental dataleToata [Memow! on, : types because they ave pwede] Type | Coyte coegined in C Aangugee. tat ky 2 to 23) ‘ed Primary data types in C Data |Mem Format oy set Speitier cha -128 to 127 “l+C 1 2 i ave of 4 types : tnt , chav, |3| float | 4 (126-28 to 3.uE +39) -/-f Hoat & double- H 8 double 3.36 -308 to 16 +09, “1 Lf ETD Me teint data type ts used to shore integer values. Range : seamen Tt can be signed ox un signed} signed tnt- Ez to aN wert has generally 32 bile (u bytesJ- ies default tnteg signed. CHARACTER Data ‘Type | The stese the § chavacters- Chasacters must be ingide sing (ancien ars if x is usually 4 byte. Range : = = a — Me Whenever we entey a character type variable, the chara- cles ts stoved as integer value tn the address Locattor oo Gr mn float data type ts used to stoye the loatin potnt numbers. The numbers that have a fractional past are callecl oating point numbers. Range: [ie = It has generally ) bytes . These can sepresent @ much laxger and vwotder range of at gt ts Qs compared! to tn ex data type. Unsigned tnt-| _¢ 4 OUE ta Type (|) The double dota type ts used to stove floating numbers . ie occupies twice as much memory iée 1 has generally & byles - Range: : (nt 9220, ° 308100. 1000, 586 ete. Chas = “olin ntl fin sy ik Uk oe La ares float — 0.7..,..0.33.,...8:21.,. 6-43 ,- tooo.29 , 562.01 ete. double - 32-334000 , 144.4692300 ete: a user defined ae type. BY Enum dot Tt is mainly used to assign . include Dae. h> names to integral constants + int maint) £ Value Assignec! must be tn range enum detter 7 a.b, df}. of signed int. enum detter y= ds Sgntoks’ enum enumnamei 5; | printf ("rd 7g): ehum enumname : setusno: 3 ¢ Specifier |B The conversion specttter chasacter neagirn whether to Intevpret the Cowsesponding argument as a Chasacter . a stsing , a pointer, an tnteger ox a Hoating number. LPT tld signed tnt did |. tong tnt bP | Pointer uy unsigned int ‘Ilid dong Long int TS] | String. skhi ghost stgned int elu | Unsigned long int “lx Hexa olectmal ise i “shoxt unsigned int — hil Unsigned Long long tnt) Lo ecta Integer ; (Naxtables—"~) ES A variable ts a name giver to an area that ous pyograms Can manipulate. CP f : WS Too main Concepts of vaviable-| void maint) ® Declavation int @ w Here, value ts ® Initialization & Usage Os 10; A ae £ . e 4 Vasiable name stasts with Lowes Q=:5; ? Wwavied, soth te, case ov underscore (_) a variable. a Int. G;.bicidee > decloving muttiple variables tn single line. (nt_ass- tnt b-s- sp declon}og & tnilializing variables. eee (eerie) BMP constant” is a vatue See can't be ener in the program: @ Chox = ‘'#', Coe BD Types chat, stsing » Integer | ‘abe’ —- X Not a char seal valued « St SK empty can't be @ String> "GATE", “Book”, char “India is my Country" ao > X Not valid, must "Newton Desk ” be in singte quotes. LOGICAL OPERATORS ====reat | NOTE # True 21 j False>o Ops: Desesiption |, | Shovt circuit incase of'£%> ac ales Ty min ei y N tf there ts @ condlitien Bnav Eada erro Rian i i iy ex pression that Z oe" Lonical oR > Ep an of the © pee ae ares: aan 9 I] ase pperands ts ai Sane Cond” after that will not evaluated : Shost cfreutt th case of |] 5) i then cond® becomes true. | | S| et theve ts a cond” anyioh- Logical AlOT > It Cs used to ert fn expression that yetusy | | s&verse the logical state of (BUC then rest of the conditions 4S operand. atter that coill not be evatuateal, labia, | BITWI: ERATORS .- Sie Oe ERAT STRUTH TABLE ava A aVaeCav 7 Opa Descxfption Pa [pet | pie __P%g a Binary AND-—> Ft copies q pit Behe ie = ° Ute the result Y Ut exits 1 Ge Bee or lease bal ® beth opexands. SPS oe ; ; Binasy OR > Tt copies a bit Uf F i f 1 exists $n efther operands . pele ake e ey Binaxy XoR-> Tt copies the bit ()e tn bitwise Left Right the ee leasing Pes? qre siUleol with Zervs. i" de}t shifting ts equivalent ty tt ls set fn only one operand. : Binary One's complement» Tt hag the effect of Hipping pits. = Binasy Left shift The values movecl Left by the numberof | BIB specitied by right operand. frnaw., t f+ —> aa eae ee ae the no. of bits specifies! « ASSIGNMENT OPERATORS | 0.73" [pj to multiplication by and 9| right sees g <| ¢ Ripht shifting is equiva- | ‘idle to dltrig on by pnd aight operand: Descai ption Opes. Des exfiption Assignment opt > Assigns valtw a [ADD & assi Aealay opts / A yxight a ee ed ah & a oes bo left apeonadl : joe rahe lopevion i Subbact ancl ascionment opt» Multiply and assienment —= (Lt cubsteacte ce vient opesang 5 ee Opt» EE mubtiplit the right and Ascion t Left operand: operand & assign to left » Divide ancl. Assignment opts Modulus and Assignment opts Tt olivioles the test opera .),. Tt takes modulus using two with the sight operand 4 operands &£ assigns the result % “ESIGN te left operand. to left operand. «=| Left shitt and assignment» >>= Right shift ancl assignment opr &= | Bttoise and assignment opr. n= Bitwise Ex-0R L assignment opr 1 Bitwise oR & assignment op MISCELLANEOUS OPERATOR [ae Sizeot) Returns the size of variable: 2 SALTZ Returns the address of vasiable- Pointer to a vartable a Conditional expression. Sieof operator [sizetU] | 72. MS circof re -putes the size of vasiable Cbyte)- a& Tt fs a unary operator. WG For float values use tke this Le io2F otheswise {t will be treatecl aS doublelio2 oF use typecasting for float and cloute- For chavacter data type te char values” use typecacting or dfrectly use datatype ox variable- Opewands can be variable, constant data type- : typ Size of ty); , Sizeof lint); , sizeof Ls); (rye “casteng ig Lt refers to changing an variable of one dala bype thto another. af The compiles ull automatically change one type of data tnto another if tt make sense. a& Types» EMPLECET TYPE PEXPLE CET ~ TYPE ® When the type conversion is pesfor-/ ® The type conversion performed -med automaticall by the compiler by the programmer by posing the voithout programmer's intesvention dato. type of expression of specftic Such type of conversion is knewon type ts Known as explictt type as implicit type tonversion of type / conversion. promotion. int % tnt x; ‘ For (x=41; Xd= 1225 X44) ae ) ne) uw 5 A vint? Une", (chav) x); Z 3 for (X=41;5 xc=122; X++) ‘aclatis C06)" x); 3