Programming in
C (ANSI C)
Dr.P.Rizwan Ahmed
Margham Publications
( For B. Sc Computer Science, B.Sc., Software Computer Science, B.Sc. ISM, B.Sc. IT, B.Sc. Software System, B.Sc. Software Engineering, B.Sc.(Physics with CA), B.Sc.(Mathematics with CA),B.Sc.(Software System), B.Sc.(Electronics), B.Sc.(Electronics and Communication Systems), B.Com (CA),B.Com(IT), BCA, MCA, and IT Professionals.)
Dr.P.Rizwan Ahmed, MCA. M.Sc., M.A., M.Phil., Ph.D, Head of the Department Department of Computer Applications & Post Graduate Department of Information Technology Mazharul Uloom College, Ambur – 635 802 Tamil Nadu, INDIA.
Margham
Publications
No.24, Rameswaram Road, T- Nager, Chennai- 600 017 Phone:(044) 2432 2469 Web Site: www.margham.in E-mail:
[email protected]
CONTENTS Preface Acknowledgement
Chapter – 1
Basic of Programming
1.1 Introduction 1.2 Problem Solving Techniques 1.3 Algorithm 1.3.1 Properties of an Algorithm 1.4 Flow Charts 1.5 Symbols Used in Flowcharts Summary Review Questions
Chapter 2
C Language Fundamentals
2.1 Introduction to C 2.2 History of C 2.3 Why use C? 2.4 Why Learn C? 2.5 Advantages / Features of C language 2.6 Structure of C -Program 2.7 Creation and Execution of a C-Program 2.8 Programming Elements 2.8.1 Character Set 2.8.2 Keywords 2.8.3 Identifiers 2.8.4 Constants 2.8.5 Escape Sequence 2.9 Data Types 2.9.1 Fundamental Data Types 2.9.2 Derived data types 2.9.3User-defined data types 2.10Variables 2.10.1 Rules for Defining Variables 2.10.2 Declaration of variable 2.10.3 Initialization of Variables / Assigning values to variables 2.10.4 Difference between Identifier and Variable 2.11 Type Conversion 2.12 Type Casting
2.13 Symbolic Constants Summary Review Question Programming Exercise Chapter 3
Operators, Expressions and Library Functions
3.1 Operators 3.1.1 Arithmetic Operators 3.1.2Relational Operators 3.1.3 Logical Operators 3.1.4 Assignment Operators 3.1.5 Increment and Decrement Operators 3.1.6 Bitwise Operators 3.1.7 Conditional Operator 3.1.8 Special Operators 3.2 Operator Precedence and Associativity 3.3 Sample C Program 3.4 Expressions 3.5 Evaluation of Expressions 3.5.1 Precedence of Arithmetic Operators 3.6 Library Functions 3.6.1 String Handling Functions 3.6.2 Mathematical Functions Summary Review Question Programming Exercise
Chapter 4
Managing Input and Output Operations and Control Statements
4.1 Unformatted I/O Functions 4.1.1 Single Character I/O 4.1.1.1 Reading a Character: getchar() 4.1.1.2 Writing a Character: putchar() 4.2 String I/O functions 4.2.1 String Input: gets() 4.2.2 String Output : puts() 4.3 Formatted I/O 4.3.1 Formatted Input: scanf( ) 4.3.2 Formatted Output : printf() 4.4 Sample C Programs 4.5 Control Statements / Control Flow / Programming Flow Control 4.5.1 Decision – Making Statement / Conditional Statements
4.5.1.1 Simple if statement 4.5.1.2 if…else Statement
4.5.1.3 Nested-if Statement 4.5.1.4 Switch Statement 4.5.1.5 Difference between switch statement and if statement 4.5.1.6 Difference between switch and n ested if statements 4.5.2.Looping Statement 4.5.2.1 While loop stat ement 4.5.2.2 Do - while 4.5.2.3 for loop 4.5.2.4 Difference between while and do-while loop 4.5.3 Jump Statement 4.5.3.1 Break statement 4.5.3.2 Continue Statement 4.5.3.3 Distinguish between Break and Continue 4.5.4 goto statements 4.6 Comma operator 4.7 Sample C Programs Summary Review Question Programming Exercise
Chapter 5
5.1 Functions 5.2 Advantages of functions 5.3 Need for user defined functions 5.4 The form of C Functions 5.5 Return Statement / Return Values and their types 5.6 Function prototype 5.7 Calling a function 5.8Formal and Actual arguments 5.8.1 Formal arguments 5.8.2 Passing arguments 5.9 Category of functions / Types of functions 5.9.1 Function with no arguments and no r eturn value 5.9.2 Function with arguments and no return value 5.9.3 Function with no arguments and return value 5.9.4 Function with arguments and return value 5.10Call by Value and Reference 5.10.1 Call by Value 5.10.2 Call by Reference 5.11 Recursion
Functions
Summary Review Questions Programming Exercise
Chapter 6
Storage Classes
6.1 Storage Classes 6.1.1 Automatic 6.1.2 External 6.1.3 Register 6.1.4. Static Summary Review Questions
Chapter 7
Arrays
7.1 Arrays 7.1.1 Advantages and Disadvantages of Arrays 7.2 Characteristics of arrays 7.3 Types of Arrays 7.3.1 One dimensional array 7.3.2 Two dimensional arrays 7.3.3 Multidimensional arrays 7.4 Strings 7.5 Sample C Programs Summary Review Questions Programming Exercise
Chapter 8
User-Defined Data Types (Structure, Union, Typedef and Enumeration)
8.1 User-defined data types 8.2 Structure 8.2.1 Defining structure 8.2.2 Structure declaration 8.2.3 Giving values to structure members 8.2.4 Structure Initialization 8.2.5 Difference between arrays and structure 8.3 Structures within Structures 8.4 Pointers to Structures 8.5 Self-referential structure
8.6 Sample C Program 8.7 Union 8.7.1 Declaration of Union 8.8 Difference between Structure and Union 8.9 Difference between Structures and Arrays 8.10 typedef 8.11 Enumerated Data Type 8.12 Bitwise Operations Summary Review Questions Programming Exercise Chatper-9
Pointers
9.1 Introduction 9.2 Definition 9.3 Advantages of Using Pointers 9.4 Application of Pointers 9.5 Accessing the address of the variable
9.6 Declaring and Initializing Pointers 9.7 Accessing a Variable through its Pointer 9.8 Pointer Operators 9.9 Operations on Pointers 9.9.1 Pointer Arithmetic and Pointer Expression 9.10 Arrays of Pointers
9.11 Pointers to functions 9.12 Pointers and Arrays 9.13 Pointers and Structures 9.14 Dynamic Memory Allocation 9.15 Command line input or arguments Summary Review Questions Chapter 10
10.1 File 10.2 Creating a file 10.3 Reading a file 10.4 Writing a file 10.5 Opening a file 10.6 Closing a file 10.7 Operations on files 10.8 Sample C Program Summary Review Questions
Files in C
Chapter 11
Preprocessor
11.1 Preprocessor 11.1 Including header files 11.2 Conditional Compilation 11.3 Macros Summary Review Questions
Chapter 12
Basic Concepts of Object Oriented Programming
12.1 Object Oriented Programming (OOP) 12.2 Features of Object Oriented Programming 12.3 Procedure Oriented Programming 12.3.1 Features of procedure oriented Programming 12.3.2 Difference between Procedure Oriented Programming and Object Oriented Programming (OOP) 12.4 Basic Concepts of OOPs 12.4.1 Objects 12.4.2 Classes 12.4.3 Data Abstraction 12.4.4 Encapsulation 12.4.5 Inheritance 12.4.6 Polymorphism 12.4.7 Dynamic binding 12.4.8 Message Passing 12.5 Benefits of OOP 12.6 Advantages of OOP 12.7 Applications of OOP / Usage of OOP Summary Review Questions
APPENDICES APPENDIX-A: Solved Problems APPENDIX-B: Questions and Answers APPENDIX-C: Practical Exercises for Thiruvalluvar University and Periyar University APPENDIX-D: Past University Question Papers APPENDIX-E: Solutions for Past University Question Papers