Top Banner
ComputerWares There are 3 types of Computer wares. 1. Humanware : The person, who can use the system, is called 'Human Ware ". He is also called as "User ". Users are in two types: i. Programmer: The person, who can develop programs, is called "Programmer". ii. End User: The person, who can use the software (developed programs), is called "End User". 2.Hardware : The physical components (devices) of a system are called "Hardware". Eg. Monitor, CPU, Keyboard, Mouse etc. 3. Software : Def: Set of related programs is called “ Software". Software is further divided into two types: i. System software: System software does not perform any task. It can manage the operating system in local machine. Eg. Operating System: DOS, Windows etc. ii. Application software: It is performing any task or solving a particular problem. This is further divided into two types: a. Packages: Collection related Applications are called "Packages". b. Languages: It is a systematical code for communication between two persons. ------------------------------------------------------------------------------------- Computer Language It is a systematical code for communication between System and user. This is in two categories. i. Low Level Language: Machine dependable language are called "Low level languages". This is further divided into two types. a. Machine language: Machine understandable language is called "Machine language". It is understandable by BINARY LANGUAGE. It is in the form of 0's and 1's. Draw back : User does not understandable that code. b. Assembly language. : It is a code language. It has some
28
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CNotes_ww8[1] (1)

ComputerWares There are 3 types of Computer wares. 1. Humanware: The person, who can use the system, is called 'Human Ware ". He is also called as "User". Users are in two types:

i. Programmer: The person, who can develop programs, is called "Programmer".

ii. End User: The person, who can use the software (developed programs), is called "End User".

2.Hardware : The physical components (devices) of a system are called "Hardware". Eg. Monitor, CPU, Keyboard, Mouse etc. 3. Software : Def: Set of related programs is called “Software". Software is further divided into two types: i. System software: System software does not perform any task. It can manage the operating system in local machine. Eg. Operating System: DOS, Windows etc. ii. Application software: It is performing any task or solving a particular problem. This is further divided into two types: a. Packages: Collection related Applications are called "Packages". b. Languages: It is a systematical code for communication between two persons. -------------------------------------------------------------------------------------

Computer Language

It is a systematical code for communication between System and user. This is in two categories. i. Low Level Language: Machine dependable language are called "Low level languages". This is further divided into two types. a. Machine language: Machine understandable language is called "Machine language". It is understandable by BINARY LANGUAGE. It is in the form of 0's and 1's. Draw back: User does not understandable that code. b. Assembly language. : It is a code language. It has some

Page 2: CNotes_ww8[1] (1)

codes for performing specific operations. This is better than machine language. Eg. ADD, SUB, MUL, DIV, ABS, FACT etc. Draw back: some codes and its operations are not easily identified by the user. ii. High Level Language : User understandable language is called "High level language". Because, it is in the form of English. Translators: Assembler: It is translating software. It translates assembly code to binary and vice versa. Compiler / Interpreter: Both are translating soft wares. Those can translate high level language to binary language and vice versa. Compiler can process a whole file at a time and it provides .exe files. But, Interpreter can process a file line-by-line only. It does not provide .exe files. This is the main difference between them. -------------------------------------------------------------------------------------

Algorithm Def: Algorithm means a step-by-step procedure for solving a particular problem. Algorithm is designed in two ways.

1. Pseudo code: It is a dummy code for solving a problem. It is designed in simple English language.

2. Flow chart : It is the graphical representation of solving a problem.

------------------------------------------------------------------------------------- Introduction to C

C is a programming language. That was designed by a man named "DENNISE RITCHIE" at AT & T Bell Labs in USA in 1972. The C programming language is a powerful programming language. Because, it is Middle level language. That means, it is machine dependable and program dependable. So, it is Middle level. This is the Mother of All programming languages. ------------------------------------------------------------------------------------- Learning Steps in 'C' : Character Set ? Word ? Instruction ? Program ? Software

Page 3: CNotes_ww8[1] (1)

Character Set : Def: All allowable symbols in this language are called "Character set". The following characters are used in this language. Alphabets ? a...z A...Z Digits ? 0,1 ... 9 Special Symbols ? + - * / % < > = ! ' " : ; . , ? | \ _ ( ) { } [ ] ~ @ # $ ^ & White spaces ? Word: Def: Group of characters is called a 'Word'. There are 3 types of words in C. i. Keyword ii. Variables and / or Identifiers iii. Constants i. Keywords :

- Keywords are the words. Those have a specific meaning defined in C compiler. So, those are called as 'Reserved words'.

- These are Pre-defined words. - There are basically 32 keywords in C.

int switch while struct long case for union short default far enum float break near typedef double goto auto void char continue regitster singed if return extern unsigned else do static const ii. Variable : Meaning: The quantity that can change their value during program execution. Def: It is a user-defined name. That is given to the memory location, where the quantity is stored. Eg. x =35 Here, the 35 is stored in the location (65000) of memory. A name given to that location is 'x'. Here, x is called variable name. Rules for constructing a variable name : 1. The name should not matched with Keyword 2. The maximum length of a variable name is 8 chars and some

Page 4: CNotes_ww8[1] (1)

compiler can allows up to 41 chars. 3. The first char. must be an Alphabet. 4. Rest of the chars. may be Alphabets / Digits / (_) are allowed

only. 5. Spaces or other special symbols are not allowed. Eg.

VALID INVALID

data auto var25 var 25 interest data,35 emp_code $var1 hello_5 _stdno DATA AUTO etc.

-------------------------------------------------------------------------------------

Operators Def: - Special symbol. - That can perform a specific operation without changing their

meaning. - All operators are special characters. But, all special characters

are not operators. Operators are classified into 3 categories.

? Unary Operators: Single operand with an operator is called “Unary Operators”. Ex. Increment and Decrement operators.

? Binary Operators: Two operands with an operator are called “Binary Operators”. Ex. Arithmetic, Logical, Relational etc.

? Ternary Operators: Three expressions with an operator are called “Ternary operators”. Ex. Ternary operators.

There are 8 Types of operators. i. Arithmetic operators : The special characters +, - , *, / and % can performing their corresponding arithmetic operations are called 'Arithmetic Operators'. ii. Relational operators : The special characters >, <, >=, <=, == and != are called Relational operators. These operators can be used for designing a condition only. Note: condition: Any two quantities are combined with a relational operator that is called

Page 5: CNotes_ww8[1] (1)

a condition. Any condition can returns either TRUE or FALSE only. But, not both at a time. syn: ( Q1 relnl.opr. Q2 ) 3. Logical operators : The special characters &&, || and ! are called 'Logical operators'. Those can perform their corresponding actions. These operators can be used for joining more than one condition. It returns either TRUE or FALSE only. But, not both. 4. Assignment operator : The special character '=' is called an Assignment operator. That means the right quantity is assigned to left side variable. syn: var = constant / var / exprn ; Eg. x = 3 // constant assignment y = x // variable assignment z = x + 10 * y // expression assignment Note : Expression means the combination of variables and / or constants with arithmetic operators. This is also called as an operand. 5. Conditional Operators [ Ternary Operators] : The symbols ? and : are called Conditional operators. Those are also called as Ternary operators. A statement formed with these two operators is called Conditional operator statement. syn: expr1 ? expr2 : expr3 ; Here, expr1 is a condition. expr2 is a true statement and expr3 is a false statement. Note: The conditional operator statement can executes only one statement (either TRUE or FALSE statement) 6. Increment and / or Decrement operators : The symbols ++ and -- are called Increment and Decrement operators. These two operators are applied to variables only. Increment : It means 1 is added to the previous value of that variable. This operator is placed in two ways.

1. Pre-increment operator: Before assigning to a variable its value will be incremented

Page 6: CNotes_ww8[1] (1)

by 1. syn. ++ var ; ==> var = var + 1; Eg. x = 5

y = ++x ? x = 6 and y = 6

2. Post-increment operator : After assigning to a variable, its value will be incremented by 1. syn. var ++ ; ==> var = var + 1; Eg. x = 5

y = x ++ ? x = 6 and y = 5

Decrement : It means 1 is deducting from the previous value of that var. This operator is placed in two ways.

1. Pre-decrement operator : Before assigning to a variable its value will be decremented by 1. syn. -- var ; ==> var = var - 1; Eg. x = 5

y = -- x ? x = 4 and y = 4

2. Post-decrement operator: After assigning to a variable, its value will be decremented by 1. syn. var --; ==> var = var - 1; Eg.

x = 5 y = x –

? x = 4 and y = 5 7. Bitwise operators: The following operators can be used for performing their actions on bit values only. Operator Meaning & Bitwise AND | Bitwise OR ^ Exclusive OR (XOR) ~ Complement >> Right shift << Left shift >>> Right shift fill with zero 8. Special Operators : The following special chars can be used for specific purposes in the

Page 7: CNotes_ww8[1] (1)

program. Operator Meaning # Pre-processor . data accessing operator -> '' (pointer ) , separator sizeof to find size of a variable -------------------------------------------------------------------------------------

Tokens Def: The smallest individual unit in a program is called “Token”. C Tokens :-

1. Character Set 2. Key Words 3. Variables and Identifiers 4. Constants 5. Operators 6. Data Types

Note: Identifiers: Identifiers refer to the names of variables, functions, arrays, classes etc. Instructions: Def: Collection of words has returns a complete meaning and ends with a semicolon (;) is called an Instruction. Types of Instructions 1. Type declaration Instructions: Any variable is used in a program that must be declaring its data type before using it. syn: datatype var1, var2 , ...; Eg. int a; float data; char grade; 2. I/O Instructions: To read data from key board (std. input device) using a statement. That is called "Input instruction". To display the information on the monitor (std. output device) using a statement. That is called "OutputInstruction".

Page 8: CNotes_ww8[1] (1)

Syn: scanf ( ) ; ? This is the standard input instruction in C. printf ( ) ; ? This is the standard output Instruction in C. 3. Arithmetic instructions: Def: These instructions can perform Arithmetic calculations. Eg. c = a+b; gross = basic + hra +da; etc. 4. Control instructions: Def: To control the flow of execution of the program using certain statements are called "Conrol Instructions ". Eg. if statement, looping statements etc. -------------------------------------------------------------------------------------

Program

Def: Set of instructions can solve a particular problem or performing a specific task is called a Program. General form of C Program: [Comment lines] including statements [defining statements] void main() { [variable declaration section ; ] [clear screen section ; ] [input / output section ; ] [processing section ; ] [getch() ; ] } [functionction definitions] comment lines : Def: Unreadable code used in a program that is called a comment. - It describes about the program. - It can be used for Identification only. - In this statement, we can use two types of symbols /* ? starting comment

Page 9: CNotes_ww8[1] (1)

*/ ? ending comment Any code in between these two symbols. That's called a comment. - It can be used any where in the program. - It can be used in any no. of times in a program. - Nested comments are not allowed. - Comments are splitted more than one line. Eg. 1. /* this is single line comment */ 2. /* this is multiple line comment */ Including statements : Def: To down load any header files using a statement. That is called "Including statement". Header file: - It is a pre-defined program. - It contains function (Sub programs), variables and constants etc. syn: # include <headerfile> Here, the symbol '#' reps. pre-processor. The word "include" is a system code. Eg. #include <stdio.h> Here, stdio.h is the name of header file. If we can download this header file, we can use the pre-defined functions and constants defined in that header file in our program. - This statement does not ends with semicolon ( ;). - It can be placed at the beginning of the program only. Defining statements: Def: To define a constant value to the var. That value does not modify through out program. - Generally it can be placed at the beginning of the program. It can be used in body of the program also. - This statement is called a 'Macro definition' or simply a 'Macro'. syn. #define template expansion Here, # ? pre-processor symbol define ? system code

Page 10: CNotes_ww8[1] (1)

Eg. #define PI 3.143 #define P printf #define M main( )

etc. Note: Generally Templates can be used as Uppercase letters. Easy to identify the templates in a program. main() : This is a user-defined function. Any function represents as follows, name( ) That can do some thing in a program. Eg. main () Here, the word main is followed by a pair of parentheses (). That represents a function.

- Each and Every C program must start its execution from this point only.

- This is defined by programmer only. so, it is user - defined function.

- Any function can return a value. but, main() function. does not return any value. Because, it is preceded by the keyword 'void '. Here, void is the one of the keyword.

Block : More than one instruction placed in a pair of braces. That represents a block of code. Eg. void main ( ) { executable statements ; ----------------------------- ; ---------------------------- ; } variable declaration section :

- This is the first section every function definition. - Any var. used in the function / program. That can be declared

it's data type before using it. Syn. Datatype var1, var2, var3, ... ; Eg. int x, data, num ; Here, the words 'x', 'data' and 'num' are vars. of same data type int . Each variable name separated by a comma and variable names and data type separated by a space, ends with a semicolon.

Page 11: CNotes_ww8[1] (1)

clear screen section : - This is the second section every function definition. - In this section, we can use a library function.

i.e. clrscr () ; It can clear the screen. That means, erases the previous output on the screen. It displays empty screen. - This function is defined in the header file, ' conio.h '. conio.h ? console input output header file. Input/output section : In this section, we can use input instructions and output instructions.

o Input instruction : Reading any type of data from KB (Std input device) using an instruction is called 'Input instruction '. Eg. scanf ( ) ;

o Output instruction : Displaying any type of data on

the Monitor (Std output device) using an instruction is called 'Output instruction '. Eg. printf ( ) ;

Here, scanf() and printf() are standard input and output instructions used in C language. These two are library functions and defined in the header file 'stdio.h'. processing section : In this section, we can use arithmetic instructions and control instructions etc. This is the body of the program. Eg. //this is arithmetic instruction c = a + b ; // this is control instruction if (cond) ---------; getch() :

- This is library function. It reads a single character. But, does not display on the monitor.

- Generally it can be used as the last statement in every C program. It can also use any where in the program except declaration section.

- It is defined in the header file, 'conio.h'. - This function belongs to console input function.

------------------------------------------------------------------------------------- Rules for constructing a c program :

Page 12: CNotes_ww8[1] (1)

There are some rules for constructing a C program. 1. It can allow only lower case letters. 2. It is case sensitive language that means, lower case and upper

case are distinct. Upper case letters can also use in a program at some places only. (Variables or constants etc)

3. Each word is separated by a space and/ or a comma only. 4. Each instruction ends with semicolon ( ; )only. printf ():

- It is a Library function. That is defined in the header file 'stdio.h'.

- It can display any type of messages on the monitor only. syn: 1. printf("MSG"); 2. printf("Formatting string " , List of variables); Here, formatting string could be, messages + conversion characters ? It must be placed in double quotes only. List of variables ? Each variable name in the statement separated by a comma and formatting string and list of variables separated by a comma. Eg: 1. printf("Welcome to C students ");

2. printf(" Roll No = %d Name = %s Average = %f " , no, name, per );

scanf() :

- It is also a Library function like printf(). It is defined in the header file 'stdio.h'.

- It can read any type of data from KB (Std. input device) only. - It is the standard input function in C language.

syn : scanf (" formatting chars " , list of vars); Here, each variable name must be preceded by a special symbol (&). '&' reps. 'Address of a variable.' Eg:

/* reading any two integer values from KB */ scanf("%d%d", &x1, &x2); /* reading emp code, name and salary */ scanf("%d%s%f ", &code, &name, &salary); Note: It does not allowed any spe. sym or msgs. gotoxy() :

Page 13: CNotes_ww8[1] (1)

- It is a pre-defined function. It is defined in the header file “conio.h”.

- It moves the control to the specific location on the monitor. syn: gotoxy(col, row);

Here, col ? 1 - 80 row ? 1 - 25 Eg. gotoxy(40,12); -------------------------------------------------------------------------------------

Control Statements Def: To control the flow of sequence of execution of a program using certain statements are called "Control Statements". there are 3 categories of control statements. 1. Branching statements : A block of code will be executed based on given criteria (condition). Eg: 1. Ternary operator statement (conditional Operator Statement) 2. if statements 3. switch statement (multiple block statement) 2. Un-conditional statements : The control will moves from one location to another location without checking any condition in a program. Eg. 1. goto statement 2. break " 3. continue " 4. return " 3.Looping (Iterative) statements : these can be used for repeating a block of code in specified no. of times or un till the condition returns false. Eg. 1. while loop 2. do-while loop 3. for loop Advantages :

- To avoid the re-writing of the same code - To reduce the length of a program - Executing time is low - Save memory space - Debugging is easy.

-------------------------------------------------------------------------------------condition: It is an expression. That is formed with relational operators. It returns

Page 14: CNotes_ww8[1] (1)

either TRUE or FALSE only. But, not both at a time. Syn: ( Q1 Relnl.opr Q2 ) conditional operator statement: The statement formed with conditional operators (ternary operators) is called "conditional operator statement". syn: expr1 ? expr2 : expr3 ; Here, expre1 is a condition, expr2 is a true statement and expr3 is a false statement. Note : It executes single statement only. if statement : Def: This is also conditional statement like ternary operator statement. But, it can executes a block of code when a cond. returns either TRUE or FALSE. There are 4 types of if statements. 1. Simple if : syn: if (cond.) { //true statements } 2. if- else statement : syn: if (cond.) { // true statements } else { //false statements } 3. nested - if statement : An if is placed in another if statement. That is called 'Nested - if '. syn: if (cond1) { // outer true statements if (cond2) { //inner true statements } else

Page 15: CNotes_ww8[1] (1)

{ // inner flase statements } } else { //outer false statements } 4. Ladder if statement : syn: if (cond1) { // 1 true statements } else if (cond2) { // 2 true statements } else if (cond3) { // 3 true statements } else { // false statements } ------------------------------------------------------------------------------------- switch stt. :

- It is similar to if - statement. - This is multiple blocks of statement. - It is also a selection statement. - Generally, it can used for Menu driven programs only.

Syn: switch( var )

{ /*beginning of the switch */ case const1 :

------------; ------------; break; case const2 : ------------;

Page 16: CNotes_ww8[1] (1)

------------; break; case const3 : ------------; ------------; break;

default : --------------; } /* end of switch */ ------------------------------------------------------------------------------------- break statement : - It is an un-conditional control statement. - It can be used as the last statement in every case in switch

statement. But, in default case need not necessary. Because, default case is the last case in switch statement. So, control will be comes out from the switch automatically.

- Generally, it can be used in looping statements also. - break preceded by an if statement in looping statements. Syn: break ; ------------------------------------------------------------------------------------- goto statement: - It is the un-conditional control statement. - It can transfer the control from one location to another location

in the same program without checking any condition. - The word goto is the one of the key word. syn: goto label ; // declaration or/and calling a label label : executable statements ; -------------------------------- ------------------------------- - When the goto statement is executed, control transfers to the

definition of the label. - Any no. of gotos can be used in a program. - But, each label must be defined uniquely. - A goto statement can use any no. of times in a program. ------------------------------------------------------------------------------------- Looping (Iterative) statements : these can be used for repeating a block of code in specified no. of times or un till the condition returns false.

Page 17: CNotes_ww8[1] (1)

Eg. 1. while loop 2. do-while loop 3. for loop Advantages : - To avoid the re-writing of the same code - To reduce the length of a program - Executing time is low - Save memory space - Easy to debug. ------------------------------------------------------------------------- While: - It is a pre-checking looping statement. That means, initially

checks the given condition. If it returns TRUE then the block of code is executed. That the block of code is executed until condition returns FALSE. If it returns FALSE then exit from the loop.

Syn: initialization ; while (cond) { -----------------------; -----------------------; updatable statements; } do-while:

- It is post-checking looping statement. - That means, after executing the block of code then the

condition will be checked. If it returns TRUE then only repeat the code otherwise control transfers to the next statement of that loop.

Syn: Initialization;

do { --------------------; --------------------; updatable statement; } while(cond) ; Note: It can execute the block of code at least once. This is the main difference between do-while and while looping statements. for :

Page 18: CNotes_ww8[1] (1)

- It is also a pre-checking looping statement like while statement. That means, initially checks the given condition. If it returns TRUE then the block of code is executed until condition returns FALSE. If it returns FALSE then exit from the loop.

- It works as same as while loop. Syn: for ( initialization ; condition ; updatable statement ) { // body of loop } - The main difference is the statements (Initialization, condition

and updatable) are in the same line in for loop. -------------------------------------------------------------------------------------

CHARACTER TYPE FUNCTIONCTIONS The following functions are defined in the header file "ctype.h". These functions are belongs to character. Function. Meaning isdigit() checks the character is digit isalpha() checks the character is alphabet islower() checks the character is lower case isupper() checks the character is upper case isalnum() checks the character is alpha numeric isspace() checks the character is space tolower() converts to lower case character toupper() converts to upper case character -------------------------------------------------------------------------------------

Arrays Def : Set of similar data elements has shared a common name called 'an Array'. Representation: varname [ size ] Here, size must be a +ve int only. size represent maximum size of an array. Types of Arrays: There are two types of arrays. Those are, i. Single Dimensional Array [1 - D array] ii. Multi Dimensional Array [n - D array] Single dimensional array : A variable name followed by a single pair of square brackets ([ ]) called 'Single dimensional array'. syn.

Page 19: CNotes_ww8[1] (1)

Datatype varname [size]; Eg. int a[5]; Here, 'a' is a variable name and 5 is the maximum size of that array. That means 'a' can holds 5 integer values. If a variable is declared as int data type that array is called 'integer array'. Similarly, 'float array'. But character array is called a 'string'. Notes: 1. Array elements are stored in sequential order in the memory. 2. Each & every array first element is stored in 0th position and its last element is stored in (size -1)th position. 3. In single dimensional array, all elements are stored in linear

order. That means, either in row wise or column wise only. Multi dimensional array : A variable name followed by more than one pair of square brackets ([ ]) called 'Multi dimensional array'. syn. Datatype varname [size1] [size2] [size3] ...[size n]; 2 - D Array : A variable name followed by two pair of square brackets ([ ]) called '2 - D array'. syn: Datatype varname[size1][size2]; Here, size1 ? max. rows size2 ? max. columns Note: 2 -D array elements are stored in matrix format. That means, rows and columns wise. Eg. int a[3][2]; Here, 3 --> rows and 2 --> columns. -------------------------------------------------------------------------------------

String Handling Functionctions

There are some pre-defined functions on strings. Those are defined in the header file “string.h”. Function. Purpose strlen() calculates length of a string strcpy() copies a string to another string strcat() concatenates two strings strrev() reversed strings of a string

Page 20: CNotes_ww8[1] (1)

strcmp() compare two strings strlwr() converts into lower case strupr() converts into upper case strstr() substring of the given string

Functionctions

Meaning: 'Do something' in a program. Def: A self contained block of code performing a specific job of some kind. That is called "Function". Repesentation: Any name followed by a pair parenthesis. syn. functionname ( ) There are 2 types of functionctions.

1. Library functionctions: Pre-defined functions. are called 'Library functions' . These are defined in the header files. Eg.

printf () scanf( ) clrscr() getch() etc.

2. User-defined functionctions: These functions. are defined by programmer only. Eg.

prime() display() getdata() etc. Notes:

- main() is a function. It has collection of function. Each and every C program must start its execution from this function. only.

- Any no. of functions can be used in a program. - A function can be used any no. of times in a program. - Any function can return a value with return statement.

Here, return is a key word. syn. return (var / const. / exprn ) ;

- It can be used as the last statement in every definition. - The void function does not return any value. The word void is

also a keyword. - A function can be called from another one.

Arguments: There are 3 types of arguments.

1. Actual arguments :

Page 21: CNotes_ww8[1] (1)

The vars., which are passing thru a function. called 'Actual arguments'.

Syn: functionname (argslist) ; Eg. add(a, b);

Here, the vars. 'a' and 'b' are called actual args.

2. Formal arguments: The variables, which are declared in a pair of parentheses at the function definition called 'Formal arguments'. syn.

returntype functionname(args list) { // body of the function. }

Eg.

void add ( int x, int y) { // body }

Here, the vars. 'x' and 'y' are called formal arguments.

3. Local variables : The variables, which are declared in a pair of braces at the function definition called "Local variables ".

syn.

returntype functionname(args list) { declaring vars. ; // body of the function. }

Eg.

void add ( int x, int y) { int z; // local var. // body of the function. } Rules for calling a specific function: 1. Calling function name should be matched with function name

in the function definition.

Page 22: CNotes_ww8[1] (1)

2. No. of Actual arguments = No. of Formal arguments. 3. The order, data types and returns must be matched. ------------------------------------------------------------------------------------- Any function. can be defined in two ways. 1. K & R method (Kernighon & Ritchie ) 2. ANSI method (American National Standard Institution) Function. def. in K & R method: syn. returntupe functionname(args. list) datatype vars ; { //body of the function. } Eg. void add ( x , y) int x, y; { //body of the function. } Function. def. in ANSI method: syn. returntupe functionname(args. list with datatypes) { //body of the function. } Eg. void add ( int x , int y) { //body of the function. } Note: Generally, we can use ANSI method only. Types of User-defined functionctions : There are 4 types of user-defined functions. i. with passing args. , with no return ii. with passing args., with return iii. without passing args., with no return iv. without passing args, with return Functionction Signature : Def: Function name followed by list of variables is called ‘Function

Page 23: CNotes_ww8[1] (1)

Signature’. Syn. Functionname (list of vars); ------------------------------------------------------------------------------------- Structures Def: Collection of dissimilar data elements has shared a common name is called “a Structure”. Syn: struct ST-NAME typedef struct { { datatype var1; datatype var1; datatype var2; or datatype var2; … … … … … . … … … … … .. }; }ST-NAME; Object construction : Syn: struct ST-NAME obj; or ST-NAME obj; Eg. struct EMP { int eid; char name[20]; char desgn[20]; float sal; }; struct EMP e; Here, e ? is an object of EMP datatype. Accessing data members : We can access the data members of a structure using dot(.) operator or pointer (->) operator only. Eg. EMP e; EMP *e; e.eid e->eid e.name e->name e.desgn e->desgn e.sal e->sal

- Structures can be defined above the main() function. Or within the main()function.

- Size of the structure means sum of the sizes of the variables

Page 24: CNotes_ww8[1] (1)

defined in the structure definition. - To calculate the size of the structure:

o int var= sizeof(structurename/ object); Eg. S= sizeof(e); Here, e ? is the object of EMP structure S ? is the var. of integer data type. Nested structures: Def: A structure with in a structure is called Nested structure. Syn. Eg. struct INNER struct DOB { { datatype var11; int dd; datatype var12; int mm; … … … … … … int yy; }; }; struct OUTER struct STUDENT { { datatype var1; int rno; datatype var2; char name[20]; struct INNER in; char course[20]; }; struct DOB date; };

struct OUTER out; struct STUDENT s; Accessing data members using outer object: s.rno; s.name; s.course; s.date.dd; s.date.mm; s.date.yy; ------------------------------------------------------------------------------------- Streams Def: Flow of bytes / characters is called Streams. There are two types of streams. Those are,

i. I /P stream: Reads data from standard input device (KB) is called i/p stream.

ii. O/P stream: Writes /displays data on to standard output device (monitor) is called O/p stream.

Page 25: CNotes_ww8[1] (1)

-------------------------------------------------------------------------------------

Files Def: Collection of information stored in a particular medium permanently is called a ‘File’. File names are 2 types:

i. Primary filename : It is designed by user. It’s max. length is 8 chars only.

ii. Extension filename : It is allotted by its application by default. It can allow up to 3 chars.

Note: - Primary filename and extension names are separated by a dot. - Each and every file can follows 8.3 rules. Eg. Hello.doc Myfile.txt Stddata.xls Total.c Palindrome.cpp Myweb.java Types of Files : There are many types in files. - Text files [The files, which are created in Notepad application only]: It can allow only chars. - Document files [The files, which are created in Ms-word application only]: It can allow text / diagrams/ pics. etc. - Data base files [The files, which are created in MS-Access application etc] - Audio / video files - Jpeg / jpg files - Image files etc. Data Base : It is the relationship between different tables. Table: The data is stored in the form of rows and columns. Row / Record : Collection of related field items in the table. A row of information represents a record in a table / file. Field: An individual data item (column) in the table is called a field. Advantages of files :

Page 26: CNotes_ww8[1] (1)

To store the data permanently. Easy to retrieve required data from a file. Etc. Operations on Files :

- Create a new file. - Open an existing file. - Close an existing file. - Store data into a file. - Adding new data to the existing file - Retrieving / reading data from a file. - Modifying / update data from in a file - Searching required data from a file. - Delete data from a file. - Copy a file to another file. - Merge of two files. - Remove a file from disc (source). - Rename a file etc.

Functionctions used in Files : The following Function are defined in the header file ‘stdio.h’. FILE :

- Pre-defined structure. - Its pointer var. can search a file from the local disc. - Its var. must be declared as pointer only. Because, it can

stores the address of opened file. Syn: FILE *fileptr; Eg. FILE *fp; - fopen() : It can be used for creating a new file or opening an existing file. Syn: FILE *fileptr ; fileptr = fopen (filename, mode) ; - fclose(): It can be used for closing opened files. Every opened file must be closed. Syn:

Page 27: CNotes_ww8[1] (1)

fclose (fileptr); - fgetc(): It reads a single character from a file. Syn: Var = fgetc(fileptr); -fputc( ) / fputch( ): It stores a single character into a file. Syn: fputc (var, fileptr); - fgets(): It reads a string from a file. Syn. fgets( var, size, fileptr); -fputs(): It stores /writes a string into a file. Syn: fputs (var, fileptr); -EOF : End Of File. -feof( ): It represents File end of File. Syn. feof(fileptr) fprintf() : It can be used for storing/ displaying the details into a file. Syn. fprintf (fileptr, “formatting string” , list of vars) ; fscanf(): It can be used for reading / retrieving data from a file. Syn. fscanf(fileptr, “formatting chars” , list of vars.) ; fwrite(): It can store / displays details of an object into a file. Syn. fwrite ( &obj, sizeof(obj), no.of objs, fileptr) ;

Page 28: CNotes_ww8[1] (1)

fread(): It can read / retrieve details of an object from a file. Syn. fread ( &obj, sizeof(obj), no.of objs, fileptr) ; rewind( ): It can move the control to the beginning of the file. Syn. rewind (fileptr) ; rename ( ): To rename a file. That means to change the name of the file. Syn. rename (oldname, newname) ; remove(): It can remove a file from disc. Syn. remove (filename); fseek(): To moves the control to the specific location in the file. Syn. fseek(location, sizof(obj), const) ; Here, const ? SEEK_BEG SEEK_END SEEK_CUR File Opening Modes There are mainly 6 types of modes in files. Those are, Mode is string only. So, it must be placed in double quotes only. Mode Meaning “ r ” Reading data from a file “ w ” Writing data into a file “ a ” Appending data to a file “ r+ ” Reading / writing data from / to a

file. Modification is allowed. “w+ ” Writing data into a file and reads

they back. Modification is allowed. “ a+ ” Appending data into a file and

reads they back. But, Modification is not allowed.