C Programming for Electronic Engineers

Similar documents
C-LANGUAGE CURRICULAM

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Practical C++ Programming

Practical C Programming. Steve Oualline

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Contents. Preface. Introduction. Introduction to C Programming


Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

C Programming SYLLABUS COVERAGE SYLLABUS IN DETAILS

CSCI 171 Chapter Outlines

Programming Fundamentals - A Modular Structured Approach using C++ By: Kenneth Leroy Busbee

Lecture 02 C FUNDAMENTALS

C Programming

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

Computers Programming Course 6. Iulian Năstac

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:

Room 3P16 Telephone: extension ~irjohnson/uqc146s1.html

Syllabus for Computer Science General Part I

C for Electronic Engineering

Computer Programming C++ (wg) CCOs

LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

Euclid s algorithm, 133

Operators. Java operators are classified into three categories:

Reserved Words and Identifiers

A Fast Review of C Essentials Part I

BSM540 Basics of C Language

Fundamentals of Programming

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Language Reference Manual simplicity

THE FUNDAMENTAL DATA TYPES

[CHAPTER] 1 INTRODUCTION 1

ощ 'ршорвшэш! цвн-эориэу ощ 'sajbpossv # PIPG DUJ 'ssjmoossv ^ PIPG pipa w н OX ЛЮН VAV

UNIT- 3 Introduction to C++

CSI33 Data Structures

These are reserved words of the C language. For example int, float, if, else, for, while etc.

Work relative to other classes

SOME ASSEMBLY REQUIRED

DETAILED SYLLABUS INTRODUCTION TO C LANGUAGE

ENGINEERING PROBLEM SOLVING WITH C++

Lecture 3. More About C

C Programming Language (Chapter 2 of K&R) Variables and Constants

OBJECT ORIENTED PROGRAMMING

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

Engineering Computing I

The Waite Group's. New. Primer Plus. Second Edition. Mitchell Waite and Stephen Prata SAMS

COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR. VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS

C++ (Non for C Programmer) (BT307) 40 Hours

ANSI C Programming Simple Programs

Model Viva Questions for Programming in C lab

Introduction to C Language

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

Java Notes. 10th ICSE. Saravanan Ganesh

Absolute C++ Walter Savitch

COMP26120: Pointers in C (2018/19) Lucas Cordeiro

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p.

Chapter 4: Basic C Operators

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

Questions Bank. 14) State any four advantages of using flow-chart

C Refresher, Advance C, Coding Standard, Misra C Compliance & Real-time Programming

Fundamental of Programming (C)

Introduction to C. Systems Programming Concepts

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

2/5/2018. Expressions are Used to Perform Calculations. ECE 220: Computer Systems & Programming. Our Class Focuses on Four Types of Operator in C

DEPARTMENT OF MATHS, MJ COLLEGE

Chapter 7. Expressions and Assignment Statements ISBN

CS1100 Introduction to Programming

Review for Test 1 (Chapter 1-5)

PROBLEM SOLVING WITH FORTRAN 90

Chapter 2 Basic Elements of C++

Computer System and programming in C

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

BITG 1233: Introduction to C++

I BCA[ ] SEMESTER I CORE: C PROGRAMMING - 106A Multiple Choice Questions.

Contents. 1 Introduction to Computers, the Internet and the World Wide Web 1. 2 Introduction to C Programming 26

PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

3. Types of Algorithmic and Program Instructions

Chapter 7. Expressions and Assignment Statements (updated edition 11) ISBN

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.

Computers Programming Course 5. Iulian Năstac

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

Problem Solving and 'C' Programming

MA 511: Computer Programming Lecture 3: Partha Sarathi Mandal

by Pearson Education, Inc. All Rights Reserved.

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

Programming Language Basics

Chapter 7. Expressions and Assignment Statements

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

Expressions & Assignment Statements

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

Programming in C++ 5. Integral data types

HUDSONVILLE HIGH SCHOOL COURSE FRAMEWORK

C Programming Multiple. Choice

Introduction to Programming Using Java (98-388)

Software Development & Education Center C Programming

Transcription:

C Programming for Electronic Engineers Keith Jackson BSc CEng MIEE with acknowledgement to Gavin Eamshaw MEng School of Electronic, Communication and Electrical Engineering University of Plymouth MACMILLAN

Preface xni 1 Introduction 1 1.1 Introduction 1 1.2 Origins of C 1 1.3 Advantages and disadvantages of C 1 1.4 Binary numbers 2 1.5 Self-assessment test - Binary 4 1.6 Binary arithmetic 4 1.7 Hexadecimal notation 6 1.8 Octal notation 8 1.9 Self-assessment test - Number bases 8 1.10 Summary 9 2 Programming Concepts 10 2.1 Introduction 10 2.2 Computer hardware 10 2.3 Operating systems 11 2.4 Memory structure 12 2.5 Machine code 13 2.6 High- and low-level languages 15 2.7 Compilers and linkers 16 2.8 Structure of a C program 18 2.9 Generalised program layout 19 2.10 Preprocessor 20 2.11 ANSI standard 20 2.12 Summary 21 2.13 Exercises 21 3 Representation of Data 23 3.1 Introduction 23 3.2 Basic data types 23 3.3 Integer types 23 3.4 Two's complement 24 3.5 Self-assessment exercise - Integers 25 3.6 Short and long integers 26 3.7 Arithmetic overflow 26 3.8 Floating point representation 27 3.9 Double and long double representation 28 3.10 Character representation 28 vii

Vlll 3.11 3.12 Summary Exercises 29 30 4 Variables and Constants 4.1 Introduction 4.2 Variables 4.3 Variable definition 4.4 Identifiers 4.5 A brief note on printf and scanf 4.6 Case study - Resistor calculation 4.7 Numerical constants 4.8 Character and string constants 4.9 Defining constants with tfdefine 4.10 Self-assessment test - Variables 4.11 Summary 4.12 Exercises 5 Arithmetic Operations 5.1 Introduction 5.2 Integer expressions 5.3 Floating point expressions 5.4 Assignment statements 5.5 Arithmetic operators 5.6 Unary + and - operators 5.7 Operator precedence 5.8 Self-assessment test - Integer expressions 5.9 Mathematical functions 5.10 Case study - Complex numbers 5.11 Arithmetic overflow 5.12 Mixed type expressions 5.13 Type casting 5.14 Self-assessment test - Mixed expressions 5.15 Increment and decrement operators 5.16 Summary 5.17 Exercises 6 Control of Program Flow 6.1 Introduction 6.2 The if statement 6.3 Boolean expressions 6.4 if-else statement 6.5 Self-assessment test - Boolean expressions 6.6 /orlloop 6.7 do-while loop 31 31 31 32 33 34 35 37 38 39 39 40 41 43 43 44 45 46 46 47 49 50 51 52 53 53 54 56 56 56 57 59 60 61 64

6.8 6.9 6.10 6.11 6.12 6.13 while loop Choice of loop type Indentation Case study - Guessing game Summary Exercises ix 65 66 67 67 70 70 7 Input and Output 7.1 Introduction 7.2 Data types 7.3 Output using printf 7.4 printf format codes 7.5 Width and precision 7.6 Escape sequences 7.7 Self-assessment test printf 7.8 Input using scanf 7.9 Self-assessment test - scanf 7.10 Problems with scanf 7.11 Reading characters with getchar 7.12 Detecting key strokes 7.13 Keyboard buffering 7.14 Detecting invalid input 7.15 Case study - Diode table 7.16 Summary 7.17 Exercises 8 Functions 8.1 Introduction 8.2 Simple procedural functions 8.3 Parameterised functions 8.4 Self-assessment test - Functions 8.5 Functions with return values 8.6 Function prototypes 8.7 Case study - Oscillator design table 8.8 Local variables 8.9 Global variables 8.10 The main function 8.11 Self-assessment test - Variable scope 8.12 Summary 8.13 Exercises 74 76 78 79 80 82 83 85 86 87 87 89 94 94 96 96 96 97 99 100 102 103 107 108 109 110 111 112 9 Arrays 114 9.1 Introduction 114 9.2 The concept of arrays 114

X 9.3 9.4 9.5 9.6 9.7 9.8 9.9 9.10 9.11 Array definitions Array subscripts Self-assessment test - Arrays Passing arrays to functions Case study - Statistical analysis Algorithm design Sorting arrays Summary Exercises 115 116 118 119 120 124 126 128 129 10 Strings 10.1 Introduction 10.2 String variables 10.3 Input and output of strings 10.4 String assignment 10.5 String comparison 10.6 Case conversion 10.7 String library functions 10.8 String value conversions 10.9 Self-assessment test - Strings 10.10 Case study - Resistor calculator 10.11 Summary 10.12 Exercises 11 File Input and Output 11.1 Introduction 11.2 File structure 11.3 Opening and closing files 11.4 Writing to files 11.5 Reading from files 11.6 Opening user-specified files 11.7 Case study - Data post-processing 11.8 Summary 11.9 Exercises 12 Pointers 12.1 Introduction 12.2 Pointer concepts 12.3 Defining pointers 12.4 The & operator 12.5 Assigning pointers 12.6 Pointer indirection 12.7 Self-assessment test - Pointers 12.8 NULL pointers 131 131 131 132 134 135 136 137 137 139 139 1 143 144 144 144 145 147 148 150 151 155 156 158 159 160 161 162

12.9 Pointers as parameters 12.10 Arrays as parameters 12.11 Pointers as return values 12.12 Absolute addressing 12.13 Self-assessment test - Pointer parameters 12.14 Summary 12.15 Exercises 13 Advanced Data Types 13.1 Introduction 13.2 The concept of structures 13.3 Declaring new types 13.4 Declaring a structure 13.5 Defining structured variables 13.6 Accessing structure members 13.7 Self-assessment test - Structures 13.8 Arrays of structures 13.9 Passing records to functions 13.10 Returning structures from functions 13.11 Case study - Telephone directory 13.12 Summary 13.13 Programming exercises 14 Low-level Operations 14.1 Introduction 14.2 Input and output ports 14.3 Controlling ports 14.4 in and out functions 14.5 The low-level operators 14.6 The NOT operator 14.7 The AND operator 14.8 The OR operator 14.9 The XOR operator 14.10 The shift operators 14.11 Case study - Temperature monitor 14.12 Summary 15 Graphics 15.1 Introduction 15.2 Display hardware 15.3 Physical coordinates 15.4 Graphics library functions 15.5 Coordinate mapping 15.6 Case study - Fourier composition XI 163 165 168 169 1 1 173 175 175 175 176 176 177 178 179 180 183 184 185 190 191 195 197 198 198 199 200 200 201 204 205 205 205 206 208 210 212

Xll 15.7 Summary 15.8 Exercises 16 Software Engineering 16.1 Introduction 16.2 Software life-cycle 16.3 Indentifying requirements 16.4 System design 16.5 Implementation 16.6 Testing 16.7 Documentation and maintenance 16.8 Software engineering using C 16.9 Separate file compilation 16.10 Makefiles 16.11 Summary 218 219 220 220 220 221 221 223 223 224 224 224 228 228 Appendix A Appendix B Appendix C Appendix D Index Glossary ASCII codes Errors in C Keywords 229 232 234 238 239