148x Filetype PDF File size 0.63 MB Source: nec.edu.np
Programming in C Notes Roshan Khatri Junior Professor Department of Computer Science and Engineering Nepal Engineering College November 11, 2016 1 CMP 103.3 Programming in C (3-0-3) Evaluation: Theory Practical Total Sessional 30 20 50 Final 50 - 50 Total 80 20 100 Course Objectives: The object of this course is to acquaint the students with the basic principles of programming and development of software systems. It encompasses the use of programming systems to achieve specified goals, identification of useful programming abstractions or paradigms, the development of formal models of programs, the formalization of programming language semantics, the specification of program, the verification of programs, etc. the thrust is to identify and clarify concepts that apply in many programming contexts: Chapter Content Hrs. 1 Introduction 3 History of computing and computers, programming, block diagram of computer, generation of computer, types of computer, software, Programming Languages, Traditional and structured programming concept 2 Programming logic 5 Problems solving(understanding of problems, feasibility and requirement analysis) Design (flow Chart & Algorithm), program coding (execution, translator), testing and debugging, Implementation, evaluation and Maintenance of programs, documentation 3 Variables and data types 3 Constants and variables, Variable declaration, Variable Types, Simple input/output function, Operators 4 Control Structures 6 Introduction, types of control statements- sequential, branching- if, else, else-if and switch statements, case, break and continue statements; looping- for loop, while loop, do—while loop, nested loop, goto statement 5 Arrays and Strings 6 Introduction to arrays, initialization of arrays, multidimensional arrays, String, function related to the strings 6 Functions 6 Introduction, returning a value from a function, sending a value to a function, Arguments, parsing arrays and structure, External variables, storage classes, pre-processor directives, C libraries, macros, header files and prototyping Pokhara University/Faculty of Science & Technology/Revised Syllabus-2012/Programming in C 1 7 Pointers 7 Definition pointers for arrays, returning multiple values form functions using pointers. Pointer arithmetic, pointer for strings, double indirection, pointer to arrays, Memory allocation-malloc and calloc 8 Structure and Unions 5 Definition of Structure, Nested type Structure, Arrays of Structure, Structure and Pointers, Unions, self-referential structure 9 Files and File Handling 4 Operating a file in different modes (Real, Write, Append), Creating a file in different modes (Read, Write, Append) Laboratory: Laboratory work at an initial stage will emphasize on the verification of programming concepts learned in class and use of loops, functions, pointers, structures and unions. Final project of 10 hours will be assigned to the students which will help students to put together most of the programming concepts developed in earlier exercises. Textbooks: 1. Programming with C, Byran Gottfried 2. C Programming, Balagurusami References 1. A book on C by A L Kely and Ira Pohl 2. The C Programming Language by Kerighan, Brain and Dennis Ritchie 3. Depth in C, Shreevastav Pokhara University/Faculty of Science & Technology/Revised Syllabus-2012/Programming in C 2 Contents 1 Introduction 7 1.1 Computer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.2 Types of Computer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.3 Basic Structure of a Digital Computer . . . . . . . . . . . . . . . . . . . 7 1.3.1 Operating System . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.3.2 Utility Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.4 Programming Language . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.4.1 Low level Language . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.4.2 High level Language . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.5 Compiler, Interpreter and Assembler . . . . . . . . . . . . . . . . . . . . 9 1.6 Traditional and Structured Programming . . . . . . . . . . . . . . . . . 9 2 Programming Logic 10 2.1 Understanding of problems, Feasibility and Requirement Analysis . . . . 10 2.2 Design FlowChart and Algorithm . . . . . . . . . . . . . . . . . . . . . . 10 2.3 Program Coding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 2.4 Testing and Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 2.5 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 2.6 Evaluation and Maintenance . . . . . . . . . . . . . . . . . . . . . . . . 12 2.7 Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 3 Variables and Data Types 13 3.1 Constant and Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.2 Variable declaration in C . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.3 Rules for writing variable name in C . . . . . . . . . . . . . . . . . . . . 14 3.4 Input Output Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.5 Operators in C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.5.1 Arithmetic Operator . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.5.2 Relational Operator . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.5.3 Logical Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.5.4 Assignment Operator . . . . . . . . . . . . . . . . . . . . . . . . 16 3.5.5 Conditional Operator . . . . . . . . . . . . . . . . . . . . . . . . 16 3.5.6 Bitwise Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.6 Operator Precedence in C . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.7 Simple Input Output Function . . . . . . . . . . . . . . . . . . . . . . . 17 3.7.1 getchar() function . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.7.2 putchar() function . . . . . . . . . . . . . . . . . . . . . . . . . . 18 3.7.3 scanf() function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 3.7.4 printf() function . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 3.7.5 gets() and puts() function . . . . . . . . . . . . . . . . . . . . . . 19 4 Control Statements in C 20 4.1 Branching Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 4.1.1 if Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 4.1.2 if..else Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 4.1.3 if..else if..else Statement . . . . . . . . . . . . . . . . . . . . . . . 22 4.1.4 Nested if Statement . . . . . . . . . . . . . . . . . . . . . . . . . 22 4.1.5 Switch Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 4.1.6 The ? : Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 4.2 Looping Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 4
no reviews yet
Please Login to review.