Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
27 views
54 pages
Module 1
Module 1 of part 1
Uploaded by
aromalvp06
AI-enhanced title
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
Download
Save
Save module 1(1) For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
27 views
54 pages
Module 1
Module 1 of part 1
Uploaded by
aromalvp06
AI-enhanced title
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
Carousel Previous
Carousel Next
Download
Save
Save module 1(1) For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 54
Search
Fullscreen
MODULE _ BASIC CONCEPTs OF PROGRAMMING sic concepts of programming A computer program is a sequence of instructions, written to form a specified task with a computer. A collection of computer ograms and related data is referred to as the software. __ Computer programming is the process of writing or editing source person who is doing computer programming is referred to asa programmer or software developer. nt of a program involves the following steps. program development hov-mmi 8 example : N!) Find factorial of anumber N( 1 le nx (Nt) x (2) ¥- .X ! a For eg: - Find the factorial of number 4 (41) = 4x3x2x1 = 94 2. Development of a model ‘Once a problem has been clearly stated, it is time to one a model. Model defines the solution to the Probie tie a a isa very important step in overall solution process. The choice of; model has substantial influence on the remainder of the solutioy process. 3. Design of an algorithm Once a problem has been clearly stated and a model has been , we must design an algorithm for solving the problem is the step by step instruction to find the answer to the An algorithm is a finite set of well defined instructions in 9 solve a program. The way in which we solve the problem rithm depends on the design of the model. Algorithm shoulé ; ive among many different ways to solve a problem. Two rithms may be correct, but may tremendously varyin thei to add two numbers entered by user. eclare Variables num1, num2 and sum. alg pr co the it ¢ an al_ Correctness of the algorithm ate, ‘Correctness of an algorithm is asserted when it is said that the mils eBrrect with respect to a specification. The most common followed to assert that a or its implemented program is it on variety of test cases. if the answers produced by in be verified against hand calculations or known values ced that it is correct, it is time to implement the code it into a computer program. ing refer to the tasks of detecting and removing it the program produces the desired result in documentation is to enable individuals to don’t write. The best way to do this is ar and self-documenting. AND FLOWCHART imethod to solve the problem is called hm is a procedure for solving Matical or computer problem, this algorithm includes calculations, s can be presented by naturalPrtran 10 Analgorithm isa finite set of well- |-defined instructions in eque egg to solve a program. An@ points. An algorithm (pronounced AL-g0o- -rith-um) is ang 4 Proved 7 formula forsolving a problem Igorithm should always have a clea ir Start a, lities of @ good algorithm Inputs and outputs should be defined precisely. Each steps in algorithm should b e clear and unambi; iguous, orithm should be most effective among many diff ifferent w, ays -a problem. algorithm she ’t have com| he jouldn’t have computer code. Instead, the al ‘ : , the algorit in such a way that, it can be used in ee imilar chart Braphi 4 Se representation of an Besa a and arrows in order Pein ioe algorithms, we can easily es ot a flowchart is to analy Braphics are applied in a flowchatt cPr proc diffe elen Hov Prog Proc So fl orga exan ExanGPrgramning i SeQuency Process / Instruction Start a ng lure Decision _ Connector / Arrow te graphics above represent different Part of a flowchart. The wehart can be expressed through boxes and arrows with Id colors. In a flowchart, we can easily highlight certain Felationships between each part, harts to Represent Algorithms ainly used for mathematical and computer charts can be used to describe all sorts of ational, personal and of course algorithms. Ised as a program planning tool to visually P process of a program. Here are some n go back to step 2cP, Flowchart: start initialize X<0 eo { tnerenert #091 i aoe Print X Be X<20 No END Convert Temperature from Fahrenheit (!) to Celsius (!) d temperature in Fahrenheit, palculate temperature with formula C=5/9*(F-32), Start 08am C-Progra Ali the pro for solv usually can be Fle proble algorit explair Rules Tl are us: how te rules tharts are diagrams that vi s. The: fe some basic shapes and boxes included in flowcharts that structure of explaining ste; n while drawing flowchart: PS of algorithms. Knowing S is crucial. Here are some W from top to bottom, a Start Box and end with a Terminal Box, benefits of a flowchart. al representation of the steps; therefore, equent steps. Standable pictorial logic and steps, entation.Cp, Progra " 4 Effective Analysis C-Prog’ Once the flow-chart is prepared, it becomes very simple en Examy the problem in an effective WaY- aly, 5 ‘ i t Useful in Coding flowc! The flow-chart also helps in coding process efficiently, asit Exam| directions on what to do, when to do, and where to do. It wae ; Ss work easier. the _ Proper Testing Further, flowchart also helps in finding the error (if any) in prog, * icable Documentation itnot the least, a flowchart also helps in preparing the prope, once the codes are written). iar f ling table illustrates the symbols along with their names y-chart) — : Symbol Name Symbol Flow Line | MagneticDisk Terminal Communication tink) P F rocessing Offline Storage _— Annotation — Flowline _ E off-page conned"& programming Bemmples of Mowctsarts Sor Nessie, analy, pose These aap or IM ReIp vou set a better understanding of flowchart techniques, gxample 1: Calculate the interest of 3 Bank Deposit Step 1: Read amount, Step 2: Read years, Step 3: Read rate, Step 4: Calculate the interest with Anterest=Amount* Years*Rate/100 tep 5: Print interest, formula nt*Years*Rate/100Algorithm: Step 1: Read number N, Step 2: Set remainder as Nm Step 3: If remainder is equal to 0 then number jy ; number Nis odd, is @ Step 4: Print output. jodulo 2, Veh Flowchart: Remainder =N modulo 2 Exampie 4: +~-~ “ty Gi Fl sy: rey esi of layerr Flowchart: “ ° a, : ar o. History of ¢ Programming Language The C language was invented at Bell Labs by Dennis Ritchie in 1972 for writing the UNIX Operating system. Among the languages available time, BCPL (Basic Combined Programming Language), )} U : : created Martin Richards in 1966, was interesting. Ken Thompson has evolved the B language from BCPL, with which he implemented the Machines. The drawbacks of the B language formed the reason M. Ritchie to develop the programming language C. So in inis M. Ritchie turned the B language into the C language, of the language B syntax while adding data-types and anges. The C language had a powerful mix of high-level d the detailed features required to program an operating - efore many of the UNIX components were eventually Se Oana 5 i the American National Standards Institute (ANS!) : mittee to provide a modern, comprehensive defaitog ing definition, the ANSI standard, or “ANS! C’, was Today Cis the most widely used System Programming a te . [a aS a S— i rogramming language du i C language is a famous P 8 eto its guy some of the qualities are: ge whose rich setup of built in func; ction, 4, It is robust Jangual d to write any com plex program. “ operator can be use program written in C are efficient due to several variety OF da types and powerful operators. The C compiler combines the capabilities of an assembly |, "with the feature of high level language. Therefore itis are ; for writing both system software and business package. Suitey There are only 32 keywords; several standard functi jlable which can be used for developing program. Ons ay portable language; this means that C programs wri itt computer system can be run on another s\ lee ste > ystem, with little, et suited for structured Programming, this re; © of a problems in terms of function or than : 1eS OF lon of these modules make a Program debuggin i . . itself. A c program is basically: : 'upported by the C library. We can F Own functions to the library with the lumber of functions. Mostly, people uset Because it is easy to learn and understand rogrammi q Bramming language because it is easy c-Progran 2 ck me Cis coll me cls 5. One byt Docum Link | Definit Global main( ) Subpro let Write a Int radius 1 Fo. Th ears,i. Cis the base for almost all Popular programming languages. Once students have learned ¢, they can / Pick up any other languages e ; Basic structure of ac Program Consists of comments, some d lescription of the | Program, programmer name and any other useful | points that can be referenced later. mentation Provides instruction to the compiler to link | function from the library function Consists of symbolic constants. Consists of function declaration and global variables. Every C program must have a main() function which is the starting point of the program } execution. User defined functions. : aa : . ' fe sections with an example int area of a circle. ample we will find the area of a circle fora given 9 F ircle i nis PI= ite the area of a circle is ar? where *'S } radius of the circle. ae A BSP A."70g Bren, 20 ec code to compute the area of the circle. Lets write th “ + file: circle.c * author: author * date: 2010-11-25 * description: program ~ using the radius F vs to find the area ofa circle include
‘#define Pl 3.1416 oat area(float r); 6.2", area()); : the following output. Comment describing the code C-Prograt / =f “1 me a of In! J and w Co and doc Lir 3.1416 Tl Create | T a> sem= i a A CProgramming ee * file: circle.c * author: authora * date: 2010-11-25 * description: program to fing th . using the radius ¢ id Ne area of a circle FNC, we can create single tine comment using two t ijanawe can create multiline comment using /**/ tas Comments are ignored by the compiler and is used to writ ocument code. eg section includes header file Ge we have created a constant P ‘Preprocessor compiler direct rally use uppercase lette Hot a statement and must -2 ction which take wenave declared an aree einen i Hoatingny | c-Prast ; n ‘ (ie,, number with decimal parts returns ga i.e-, at number. i ‘ A main() function to rept This section contains the main() function. numbé —__ ~ Alp int main(void) as : Dig float r= 10; ‘Spe printf(“Area: %.2f”, area(r)); return 0; i peer compi isis the main() function of the ide thi me ating variabl e code. Inside this functionwetg, Build le r and assigned 10 to it. * @a€ pr c gba oa NE area() function. It receivesthe val “turns the area of the circle usingC-Pragrammiing B The C Character set A character denotes any alphabe: to represent information. The table b fumbers and special symbols allowed ‘Alphabets & digit or special symbol used elow shows the valid alphabets, inc. yee a,b, Vz 0,1,2,3,4,5,6,7,8,9 ~T@#®*B9() += 1\() 0 Digits Special symbols C tokens in 2 C source program, the basic element recognized by the isthe “token.” A token is source-program text that the compiler ‘breakdown into component elements. C tokens are the basic blocks in C language which are constructed together to write are of six types. They are, (eg: int, while), (eg: main, total), (eg: 10, 20), (eg: “total”, “hello”), (ee: (), {}), (eg: +, /,-,*) %d \n”, total);a where, main identifier ook + 4h ()- delimiter : «© int- keyword identifier . xy, total — int, X,Y» total — tokens @ main, {,},(), Basic Building Blocks and Definition: ee Meaning Ba A variable is a meaningful name of ioe 9 location in computer memory. When uh Ba variable you refer to memory address of compu ae Constants are expressions with a fixed value Pai ne 57 ee The term identifier is usually used for Variable names a Sequence of characters C lide ee | Symbols other than the Alphabets and Digitsand | white-spaces variak of arb A A symbol that represent a specific mathematica eh : Or non mathematical action ; identi Example 1 Example? Do while Number | ae “UTE” e | * —| at .EERE a ig Programming tokens can be further explained as follows: (CKeywords const default do Double | else | extern float For | goto | int long | register return | signed sizeof Static struct typedef. | union unsigned | void | fe Used as the general terminology for the names of ind arrays. These are user defined names consisting ince of letters and digits with either a letter or | first character. Tules that should be followed while naming c d as naming convention ith a letter or underscore(_). st of only letters, digits, or underscore. No other allowed. rd. e space. acters long as only first 31 characters are26 Gee a ee “invalid as it cont Pe erccare g bee no invalid as tis a keyword ains special character oth, le mp.var Temp. "thang C Constants constants refers tot during the program execution. allowed in Care: 4. Integer Constants he data items that do not change t hej Several types of C constants st , hat ay Integer constants are whole numbers without any fra : ust have at least one digit and may contain either ae on Psi wae es n ber with no sign is assumed to be positive. 2 consisti Bots ie Of sequence of digits from the se!’ i 0 be octal integer constants. ; Octal integer constants fe. cons: ‘ i tants are integer constants Ny Ox OX. They may also include al ha’ phate Progra Exe oxt Its are rare| 2. Real The constar called ft or - sig! Ex notatior Oo. 3. Char Ac single q Ex It: known ASCII v: Escape IG. Constar typed ¢ Tt Sequer charact N "epres,sel —— ins special character ot invalid as it contains SP! icter other th, es thy pone ig fet GU ore it is a keyword 0 the data items that do not change t, ei Cconstants refers t cution. Several types of C constants 4 during the program exe allowed in Care: 4. Integer Constants ira hata, Integer constants are whole numbers without any fractio ie al pa ust have at least one digit and may contain either + or = ~ Sing nber with no sign is assumed to be positive. u sre are three types of integer constants: instants consisting of a set of digits, 0 — igits, O through 9, prec tS consisti t Bas eis of sequence of digits from thes! i aid to be octal integer constants. Octal integer constants Eonstants are integer constants rai Y Ox or OX. They may also include alphab Pers 10 to 15. c-Progre Ex Ox it are rare 2. Real Tr consta called f or-sig B notatic 0. 3. Cha A single «Example of valid hexadecimal integer constant ants ‘OxD, OX8d, OX, OxbD it should be noted that, octal and h, . }exadecimal i rarely used in programming. Scimal integer constants +2. Real Constants The pee having fractional parts are called real or floating point aie Mey be represented in one of the two forms fractional form or the exponent form and may also ha e either + f and may al Fa. v ve either Constants constant contains one single character enclosed within valid character constants are ‘a’, ‘Z’, ‘5’ that character constants have numerical values is, for example, the value of ‘A’ is 65 which is its Escape Sequences have certain non graphic characters in character echaracters are those characters that cannot be yboard, for example, tabs, carriage return, etc. haracters can be represented by using escape a backslash() followed by one or more ence consumes only one byte of space asit28 eee: Audible alert(bel!) a Be [See eee Backspace - eae ee Form feed F a New line Carriage return Horizontal tab Vertical tab Backslash Double quotation mark Single quotation mark Question mark Null elistant is automatically terminated with a sPe null character which represents the end Ci Will represent “hello” in the memory H us ng is the total number of characte”? Br and en statemé Pa calls an Br referen variable are call data. It Way to Sasi jcy PS an, . ing capagramming special Symbols 29 The following special symbols are used in C hy aving some special sreaning and thus, cannot be used for some ather special purpose Mit,s:* = 9 Braces{}: These opening and ending curley braces marks the start end of a block of code containing more than one executable sll: Opening and closing brackets are used as array element These indicate single and multidimensional subscripts. are symbols that triggers an action when pli F objects. The data items on which operators act upon in the number of operands that an operator can act ‘be classified as follows: Those operators that require only single operand known as unary operators. Those operators that require two operands to d binary operators. S: These operators require three operands to act Variables in C Of the memory location, It is used to store imes. Itisa and it can be reused many times. It's Ocation through symbol so that it can be OS aSCProgray Avariable is an identifier that is use d to represent some Spec; type of information within a desi ignated portion of the Program. j ntifier that is used to representa s) fey its Simplest form, a variable is an ide: ingle data ariable at some point in the Program data item; i.., a numerical quantity or a character constant. The item must be assigned to the vi The data item can then be accessed later in the program simply by ferring to the Variable name. A given variable can be assigned different data items at Various laces within the program. Thus, the information represented by the variable can change during the execution of th ita type associated with the variable can 9€ belonging to any of the data type like i € program. However, the not change. C variable might nt, float, char etc. ‘Jor naming C variable: iable name must begin with letter or underscore. #5 are Case sensitive | be constructed with digits, letters, Isymbols are allowed other than underscore. Value are some examples for variable name Cvariable: id be declared in the C program before to use. lace is not allocated for a variable while happens only on variable definition. ‘ation means assigning a value to the variable Syntax Example type variable_name; int x, y, 2; char flat ch; | \_type variable_ le = value; int x = 50, y = 30; char flag =x’, ch CPro varial storal data | follov lee I float, consis valid © declar. Consta —— [typev.eProgranimins yariable Definition inc Here, type must be a valid C data ty t, double, bool, or any use r-define, jist Of one or more identifier nami iclarations are shown here “ 4 object; and variable_tst may es separated by commas. Some initialized (assigned an initial value) in their lizer consists of an equal sign followed by a s follows - U/ declaration of d and f. definition and initializing d and f. / definition and initializes z.32 C-Progran For definition without an initializer: variables with static duration are implicitly initialized with NULL (; the initial value of all other variables are u Storage all bytes have the Value g) indefined. Declaration of Variables A variable declaration Provides assurance to the compiler thay here exists a variable with the given type and name so that the compile, in proceed for further compilation without requiring the complete tail about the variable. A variable definition has its meaning at the of compilation only, the compiler needs actual variable definition time of linking the program. Avariable declaration is useful when you are using multiple files 0 U define your variable in one of the files which will be available me of linking of the program. You will use the keyword extern to a Variable at any place. Though you can declare a variable your C program, it can be defined only once in afile,a ock of code. example, where variables have been declared at been defined and initialized inside the main C-Prograr int int: floz prir prir rete } Whi following valu valu Types of The el 2 3. 4. 5. Icint a, b; int c; float f; | = /* actual initialization */ is of variables in c:Program, Local Variable cl A variable that is declared inside the function or block is Called, local variable, the he It must be declared at the start of the block. a void function1(){ Au int x=10;//local variable } vari ei usir You must have to initialize the local variable before it is used, Global Variable __ Avariable thatis declared Sutside the function or block is called a I variable. Any function can change the value of the global variable, Exte exter keyw IS declared with the static keyword is called static ‘ q 1 : . i ie between multiple function calls. Vv (){ variable ! /static variable Can Ste USeq 4,_cbmmgravenins __tfyou call this function many times, “se same value for each function call, e. tic variable will print the increm 11, 12, 13 and so on. 35 the local variable will print *8, 11,11,11 and so on. But 'ented value in each function lables in C that are declared inside the block, are automatic ‘by default. We can explicitly deciar: keyword. e an automatic variable [/\ocal variable (also automatic) -20;//automatic variable inc ita storage format that a variable specific operation. Data types are € in a program. Size of variable, lata types._ 36 Programs. " A program Csupports several different types of data, each of which may, © Fepresented differently within the computer's memory. The basicqy, Primary "types are listed below. Typical memory requirements are also gi, —_—Eve! (The memory requirements for each data type will determine the armissible range of values for that data type. Note that the Memon, juirements for each data type may vary from one C compiler te other.) Adata-type in C programming is a set of values and is determine, act on those values. C provides various types of data-types whic: w the programmer to select the appropriate type for the variable its value, float, dc int *, fle data-type in a programming language is the collection of dat: ing fixed meaning as well as characteristics. Some o Declarat floating point, character, etc. Usually, programmin; Afte t the range values for given data-type. —_—* Example d to: ‘ 5 int of a variable when it declared. ; che pe of the return value of a function Fic pe of a parameter expected by a function. Se : Derived three types of data types: Csa = Ba, Te AS ee comer 37 ‘Data Types ery Ccompiler supports five primary data types: As the name suggests, it holds no value and is generally used for specifying the type of function or what it returns. If the function has a void type, it means that the function will not return any value. || Used to denote an integer type. | Used to denote a character type. | Used to denote a floating point type _Used to denote a pointer type. ry Data Types with Variable Names lable names, they need to be assigned with types are used along with variables: iption es of data items having ey have adjacent memory rencing functions with a | ptures which are used to Iiwith their addresses. |C-Prograiny, ; O\ g-prograt User Defined Data Types Int alloy, ame nu Cxisti, 40 to it C allows the feature called type definition which Programmers to define their identifier that would represent an a type. There are three such types: Bemeteer ee hy Description Itis a package of variables of different types under a single name. This is done to handle data efficiently, “struct” keyword is used to define a structure. These allow storing various data types in the same memory location. Programmers can define a union with different members, but only a single member can contain a value at a given time. Enumeration is a special data type that consists of | The abo integral constants, and each of them is assigned with Scc specific name. “enum” keyword is used to define enumerated data type. ent z — defined use the typedef keyword to give new identifier 2 to aexisiting data type. Usi x — can In eyword to give new identifier name toa type col Next we value G} 0 use typedef is given below. ing data type and identifier is the new nam? eger int data type anewname nu”jnthe ere example we have used typedef to give int a new ‘And then created a new variable and assigned integer value te a data type and also define the value ible of that type. we are creating an enumerated data values RED, GREEN, BLUE and WHITE EarColor of type color and assigning thead C-Prograny, We can combine the enum definition and variable creation 85 folloy, enum color { RED, GREEN, BLUE, WHITE }carColor = GREEN; By default, the compiler assign integer value to the enum constants Starting from 0. So, in the above color enum th e RED constant gets the integer value O, GREEN is assigned 1 and so on. The following code will print “Car Color: 1” a‘ as output since the num constant GREEN gets the integer value 1. __ #include
a i in(void) GREEN; lor: %d\n”, carColor); own integer value to the enum constants. to 2 enum constant then the successiv? creases by 1, é cPre follo Basicprograming 41 For example, if we want to set GREEN to 2 then we can write the olor = GREEN; will be 0 (default as enum constant value starts from 0) ill be 2 (we have set that value). 3 and WHITE will be 4. Ows a variable to store numeric values. d to refer integer data type. itdata type is 2 or 4 or 8 byte processor in the CPU that we use. Ifwe SS0F, 2 byte (16 bit) of memory will be memory for 32 bit processor and 8 byte bit processor is allocated for int datatype. 8s from -32,768 to +32,767 values from -2,147,483,648 to Value that crosses the above limit, ong long int” for which the limitsWe tan combine the enum defi enum color { REO, GREEN, BLUE, is assigned 1 and so on GREEN r following code will print “ GREEN gets the BLUE w - Basic data t intege: © Integer © “int* ke © The sto varie: are us’ allocate Ukewis, (Sibi m R bd int (4 2247, yoy ‘e You fan Very integer value to the enu BO @ enum constant then ses by 1. OSye. a C-Programm, (C-Program Note: © . We can’t store decimal values using int data type oe © _ Ifweuse int data type to store decimal values, decimal values yi aes le number. be truncated and we will get only whole n ei ‘* _ Inthis case, float data type can be used to store decimal values), a avariable. variat Character data type: Brot es © Character data type allows a variable to store only one character proce Storage size of character data type is 1. We can store only one byte. character using character data type. * There “char” keyword is used to refer character data type. 1. sh For example, ‘N’ can be stored using char datatype. You can’t store 2. lor than one character using char data type 3. si ‘point data type: aur data type consists of 2 types. They are, 5. lo © Belo data and} proc ‘type allows a variable to store decimal values. size of float data type is 4. This also varies depend upot or in the CPU as “int” data type. Type | @ up-to 6 digits after decimal using float data type.Programming Modifiers in c: The amount of memo; TY Space to _ derived by modifies be allocated for a variable is 'Ount of storage space all variable. BE Spi located toa * For example, storage space for int data Processor. We can increase the range by byte. We can decrease the range by using type is 4 byte for 32 bit using long int which is 8 short int which is 2 byte. There are 5 modifiers available in c lang 1. short 2. long signed unsigned . long long jelow table gives the detail about the storage size of each C basic in 26 bit processor. Please keep in mind that storage size j¢ for int and float datatype will vary depend on the CPU Sor (8,16, 32 and 64 bit) age. They are, Memory =| Requirement| Range of Values in Bytes 4 —2,147,483,648 to 2,147,483,647 4 Oto 4,294,967,295 2 —32,768 to 32,767 Oto 65,535 —9,223,372,036,854,775,808to | 9,223,372,036,854,775,807_44 CProgrammi tnsignediong | a | Oto 18,486, 744,073,709 S16 Boolean 1 falseortrue Char 1 Any Characters numbers orsymba Short Hata Bazest3i,767 unsigned short A 0 to 65,535 ai 4 | floating-point number (i.e. a number containing a decimal point and/or an exponent) double-precision floating-point number (i.e., more significant figures, and an exponent which | maybe larger in magnitude) same as double | Same as double lic Constant is a name that substitutes for a sequence of z lers may represent numeric constant, a character Onstant. Thus, a symbolic constant allows a name @ numeric constant, a character constant or a mbolic Constant: stant is declared as follows: name value of constant constant definitions are C-Programmi symbe the symbol the follow’ symbolic co 1. Syn (syr ther low 2. No! per 3. de 4. Abl and 5. Sym Advantage: 1. tr 2. itm 3. itm 4. The dev For ex: the informa Suggest the Operators ; An ope Mathematic 8nd providec-Programming 45 Symbolic constants are sometimes called constantidentifiers. Since the symbolic names are constants they do not appear in declarations. he following rules apply to the #define statement which defines a _gymbolic constant. Kk space is required between define and symbolic name feen the symbolic name and constant hames are not declared for data types. ms more powerful m modification easier. lended since, they contribute to the ‘orderly program stants are more readily identified than resent, and the symbolic names usually associated data items.perme 45 bolic names have the same form as variable names. bolic names are written in CAPITALS to visually distinguish m from the normal variable names which are written in letters. This is only a convention, not a rule.) space between the pound sign and the word define is ‘student must not end with a semicolon. ‘Space is required between define and symbolic name sn the symbolic name and constant 8s are not declared for data types. Constant: ms easier to understand and readable. \s More powerful. modification easier. ended since, they contribute to the 5 orderly program. onstants are more readily identified than sent, and the symbolic names usually associated data items iC ells the compiler to perform specific iC language is rich in built-in operators ‘operators “= | Oto 18,446,744,073,709,551 6). unsigned long 8 1 | false or true 1 ‘Any Characters numbers or symbol 2 ~32,768 to 32,767 2 | 0 to 65,535 a floating-point number (i.e., anumber containing 4 decimal point and/or an exponent) double-precision floating-point number (i.e., more significant figures, and an exponent which maybe larger in magnitude) same as double | Same as double stant is a name that substitutes for a sequence of ers may represent numeric constant, a character instant. Thus, a symbolic constant allows a name Of a numeric constant, a character constant or 4 symbolic Constant: ant is declared as follows: __name value of constant Constant definitions are 100 50 200 3.14159 qe on * on ne’ iow 2 per 3. ee 4 At am 5. Sys Advantag zs 2 3 ft A cr For46 C-Programns, Arithmetic Operators Relational Operators Logical Operators * Bitwise Operators * Assignment Operators * Conditional Operators Arithmetic Operators The following table shows all the arithmetic operators supported Description Example Adds two operands. A+B=30 | Subtracts second operand from the first. | A“B=-10 Multiplies both operands. A*B=200 livides numerator by de-numerator. dulus Operator and remainder of ran integer division. fement operator increases the ger value by one. ment Operator decreases the r value by one. ProgrammiChecks if the values of two operands are equal or not. Ifyes, then the condition becomes true. (A == B) is not true, Checks if the values of two operands are equal or not. If the values are not equal, then the condition becomes true (A !=B) is true. Checks if the value of left operand is greater than the value of right operand. Ifyes, then the condition becomes true. (A> 8) is not true. ks if the value of left ind is less than the je of right operand. ;greater than or e value of right ; es, then the yecomes true. e value of left ess than or equal right operand. ‘condition (A
=B) is not true (A<=B)istrue.C-Programmin, 48 C-Progra rs Logical Opersto ; Th Following table shows all the logical operators supported by ¢ Janguage. Assume variable A holds 1 and variable B holds 0, then “ Assume Description Example Operate Called Logical AND operator. 1 & If both the operands are non-zero, | then the condition becomes true. (A && B) is false, | I Called Logical OR Operator. If any | eee of the two operands is non-zero, I then the condition becomes true. (A || B) is true. Called Logical NOT Operator. A It is used to reverse the logical state | of its operand. If a condition is true, | then Logical NOT operator will make it false. | (A && B) is true. ~ &, |, and “is as follows “ << p&q pla p%q 0 0 0 0 ay a 1 L 1 O | Een 0 1 1. ae ‘and B= 13 in binary format, they will be as follows’ — Assignmer The fi¢Pmgramming The following table lists the bitwise o} ‘assume variable ‘A’ holds 60 and variable perators supported by C. ‘B’ holds 13, then “ 49 loperator Description Example @ Binary AND Operator copies a bit to the result if it exists in both operands. (A&B) = 12, i., Binary OR Operator copies abit if it exists in either operand. 0000 1100 (A | B)=61,ie., 0011 1101 Binary XOR Operator copies the bit if it is set in one operand but not both. Binary One's Complement | Operator is unary and has “the effect of ‘flipping’ bits. ary Left Shift Operator. left operands value is ed left by the number ry Right Shift Operator. left operands value d right by the of bits specified 0111101 | (ane)=49,ie, | 0011 0001 (-A)="(60),ie, | A<<2=240i.e., 41110000 | A>>2=15i.e, ight operand. ble lists the assignment LD. OD cae 5 00001111 operators supported ByDescription C-Programm:, Simple assignment Operator. Assigns values from right side operands to left side Operand Add AND assignment Operator. It adds the right Operand to the left operand and assign the result to the left operand. value of A+B toc C=A+B will assign the C += Ais equivalent to C=C+A Subtract AND assignment Operator. It subtracts the fight operand from the left Operand and assigns the _fesult to the left operand. tiply AND assignment fator. It multiplies the Operand with the left ind and assigns the to the left operand. AND assignment OF. It divides the left and with the right C-= Ais equivalent to C=C-A eee | C*= Ais equivalent to C=CtA C/= Ais equivalent to C=C/A C-Programmin, foxx | Conditional Of Besides 1 important op Language. Operator | sizeof()| Re C %= A is equivalent #9 "ators Prece, C=C%A Operator : ®XPres, Sion ana_ eens a” OK Left shift AND assignment] Cxee Bas ial ‘<= 2is same as : C=C
his a header file used for input.output purpose.“ prec nting each time. nd prefix mode for b. (//Print them and decreme! /Jse postfix mode fora ai printf("\n%6d %6d”,a—,—b)i printf("\n36d %d",a—,—b) printf(“\n%d %d”,a—,—b); printf(“\n9%d %d”,a—,—b); printf(“\n%d %d”,a—,—b); #f Expressions ion is a sequence of operands and operators that gle value. For example, the expression, 10+5 reduces to rators and operators used in the expression, they ral types. Some of them are: ssions — expressions which contains integers and sions — expressions which contains floating point ‘Operators pressions — expressions which contain operands tic operators le arithmetic expressions — expressions which ger and real operands ons — expressions which contain relation® ands Is — expressions which contain logi¢? fands Programming 7. Assis cont expression E Expressi form: In the al the statemen evaluated firs hand side. All varial values before Expressi associativity r Operator Pri Every C This preceder than one ope There ar May belong t: Precedence < Precedence a Nn the associ In the b perators anc level. Rank o Highest prece _ The prec 8iven below =GONE SS SF CProgramming epmgraming aw 35 Ament expression: S and so on... — contain assignment operators and erase Presions which xpression Evaluation a Expressions are evaluated a me using an assignment ‘Statement of the Inthe aan syntax, variable is any valid C variable name. When Bere Pete Re form is encountered, the expression is evalu en the value is assigned tc oy ie ign to the variable on the left Allvariables used in the expression must be declared and assigned before evaluation is attempted. Examples of expressions are: ions are evaluated based on operator precedence and rules when an expression contains more than one operator. recedence and Associativity ‘operator has a precedence (priority) associated with it. s¢ is used to determine how an expression involving more boats ator is evaluated. wa different levels of operator precedence and an operator 0 one of these levels. The operators at the higher level of za ‘are evaluated first. The operators in the same level of at 4 ‘evaluated from left to right or from right to left, based ; property of an operator. 5} slow table we can look at the precedence levels of * { 6 the associativity of the operators within the same : jeates the lowest precedence and Rank 14 indicates » as ce and associativity of various operators in C are as‘Cprograming t ae the devices as files. So devices such as the ae pe ame Way as files and the following three ened when a program e to the keyboard and screen, a ae File Pointer | stdin Device Keyboard _| stdout Screen | stderr Your screen | iters are the means to access the file for reading and is section explains how to read values from the print the result on the screen. tchar() Functions (void) function reads the next available character d returns it as an integer. This function reads only & time. You can use this method in the loop in case ore than one character from the screen. r{int c) function puts the passed character on the se same character. This function puts only single You can use this method in the loop in case you an one character on the screen. Check the
You might also like
Programming for Problem Solving Theory 2020-21
PDF
No ratings yet
Programming for Problem Solving Theory 2020-21
162 pages
Planning of Computer Programming-In Today Word A
PDF
No ratings yet
Planning of Computer Programming-In Today Word A
16 pages
Edited - Cfap - P.L.
PDF
No ratings yet
Edited - Cfap - P.L.
118 pages
C Programming PDF
PDF
No ratings yet
C Programming PDF
119 pages
3 Algorithm
PDF
No ratings yet
3 Algorithm
33 pages
1.1.3 Algorithm
PDF
No ratings yet
1.1.3 Algorithm
33 pages
C Note Upto Loop
PDF
No ratings yet
C Note Upto Loop
78 pages
C Programming Part 2
PDF
No ratings yet
C Programming Part 2
10 pages
Computer-Programming - C - Lecture-Notes Acme PDF
PDF
No ratings yet
Computer-Programming - C - Lecture-Notes Acme PDF
148 pages
ccs-2101-introduction-to-programming-in-c-notes-1-3-1
PDF
No ratings yet
ccs-2101-introduction-to-programming-in-c-notes-1-3-1
27 pages
Cat1 C
PDF
No ratings yet
Cat1 C
84 pages
Session1 - 3 - Introduction To Algorithm I - Final
PDF
No ratings yet
Session1 - 3 - Introduction To Algorithm I - Final
101 pages
64cf60e1-dd87-436e-b2be-be9b5156e823
PDF
No ratings yet
64cf60e1-dd87-436e-b2be-be9b5156e823
205 pages
Part 1 Handout Intro to Programming With Python
PDF
No ratings yet
Part 1 Handout Intro to Programming With Python
46 pages
Notes-1
PDF
No ratings yet
Notes-1
10 pages
Lec 2 - Programming Language, Algortihm, Pseudocode, Flow Chart
PDF
No ratings yet
Lec 2 - Programming Language, Algortihm, Pseudocode, Flow Chart
27 pages
Pps Notes
PDF
No ratings yet
Pps Notes
204 pages
GR24 PPS material
PDF
No ratings yet
GR24 PPS material
194 pages
CS101E-PSP- Part I
PDF
No ratings yet
CS101E-PSP- Part I
60 pages
Chapter_1_Introduction to Algorithms and C
PDF
No ratings yet
Chapter_1_Introduction to Algorithms and C
66 pages
APznzaan_OyAH4nnNVM2ehVv11_rq5yt5KN4a5Pt8b2fCa-j-a-nLaL-P9ZzvwTI0HQa36mBDm8gt6ugh9j00BqR5MMI0d74wUgNrHvqCfSepprS4CG0MXWagHXYttdmtmSXgstn4KsFIRYU-t9iKMSWinHVp8jByKasCmPBCwU4kkzUL890EfgJjDJLrWa7qkyfKAbBYiLh
PDF
No ratings yet
APznzaan_OyAH4nnNVM2ehVv11_rq5yt5KN4a5Pt8b2fCa-j-a-nLaL-P9ZzvwTI0HQa36mBDm8gt6ugh9j00BqR5MMI0d74wUgNrHvqCfSepprS4CG0MXWagHXYttdmtmSXgstn4KsFIRYU-t9iKMSWinHVp8jByKasCmPBCwU4kkzUL890EfgJjDJLrWa7qkyfKAbBYiLh
32 pages
Introduction To Programming
PDF
No ratings yet
Introduction To Programming
106 pages
Lecture # 1 (15-02-2023)
PDF
No ratings yet
Lecture # 1 (15-02-2023)
43 pages
C Language I Semester
PDF
No ratings yet
C Language I Semester
77 pages
Chapter 4
PDF
No ratings yet
Chapter 4
147 pages
Unit 1-1
PDF
No ratings yet
Unit 1-1
105 pages
Unit 1
PDF
No ratings yet
Unit 1
23 pages
C Programming_Unit 1 Final Ppt
PDF
No ratings yet
C Programming_Unit 1 Final Ppt
75 pages
CH 1
PDF
No ratings yet
CH 1
36 pages
BCA I Sem - C Programming-1
PDF
No ratings yet
BCA I Sem - C Programming-1
72 pages
Programming1 Lecture Presentations
PDF
No ratings yet
Programming1 Lecture Presentations
124 pages
PPS Unit 1
PDF
No ratings yet
PPS Unit 1
132 pages
UNIT-1 PPT
PDF
No ratings yet
UNIT-1 PPT
83 pages
Chapter 1 2 3 4 5
PDF
No ratings yet
Chapter 1 2 3 4 5
107 pages
Unit1 C Sreedhar
PDF
No ratings yet
Unit1 C Sreedhar
27 pages
L05!06!07 ProblemSolving
PDF
No ratings yet
L05!06!07 ProblemSolving
76 pages
UNIT I: Programming Fundamentals: 1.0 Learning Outcomes
PDF
No ratings yet
UNIT I: Programming Fundamentals: 1.0 Learning Outcomes
11 pages
Module 1-1
PDF
No ratings yet
Module 1-1
65 pages
Lecture 01
PDF
No ratings yet
Lecture 01
44 pages
C Programming
PDF
No ratings yet
C Programming
120 pages
Unit 1-PSC
PDF
No ratings yet
Unit 1-PSC
137 pages
45d06462-d0f8-4f84-825e-f56c1d68dcc1
PDF
No ratings yet
45d06462-d0f8-4f84-825e-f56c1d68dcc1
46 pages
Module 1
PDF
No ratings yet
Module 1
79 pages
Week 2
PDF
No ratings yet
Week 2
44 pages
C Language
PDF
No ratings yet
C Language
82 pages
COMPUTER PROGRAMMING
PDF
No ratings yet
COMPUTER PROGRAMMING
15 pages
Unit 1 Introduction
PDF
No ratings yet
Unit 1 Introduction
55 pages
C
PDF
No ratings yet
C
14 pages
Concept of Programming
PDF
No ratings yet
Concept of Programming
7 pages
Programing with C VVI QUESTIONS WITH ANSWERS
PDF
No ratings yet
Programing with C VVI QUESTIONS WITH ANSWERS
1 page
Structured Programming With C Language
PDF
No ratings yet
Structured Programming With C Language
47 pages
2.basics & Algorithm-Flowchart PDF
PDF
No ratings yet
2.basics & Algorithm-Flowchart PDF
51 pages
Module 1 Notes
PDF
No ratings yet
Module 1 Notes
7 pages
Problem-Solving v2
PDF
No ratings yet
Problem-Solving v2
6 pages
Problem Solving Tech
PDF
No ratings yet
Problem Solving Tech
40 pages
BCA I Year C Notes
PDF
No ratings yet
BCA I Year C Notes
36 pages
1b) SMA 2175 Introduction To Programming in C Notes - 1-3
PDF
No ratings yet
1b) SMA 2175 Introduction To Programming in C Notes - 1-3
26 pages