1 Programming in C: an Overview.............................1 1.1 C Program Development Cycle..................................................2 1.2 Basic Programming Tools and Concepts....................................4 1.3 Playing with Basic C Language Primitives and Data Types.......6 1.3.1 C Program Skeleton or Structure...................................................7 1.3.2 Create Your First C Program ........................................................9 1.3.3 Understanding Preprocessor-generated Files...............................14 1.3.4 Compilation Process and Error Classes.......................................18 1.3.5 Playing with Semantic and Syntax Errors ..................................22 1.3.6 Playing with Runtime Errors: the Debugging Process ...............25 1.4 Playing with Type Definition, Arrays and Structure ................31 1.5 Playing with C Language Constructs........................................35 1.6 Playing with C Function and Pointer........................................462 Hands-on Functions..............................................54 2.1 Algorithm and Programming....................................................55 2.2 Function Declaration and Definition.........................................62 2.3 Function Call Types and Their Mechanisms.............................68 2.4 Function and Programming Modularity....................................72 2.5 Function Scope and Variable Lifetime......................................81 2.6 Recursive Function...................................................................963 Hands-on-Pointers: The Basics..........................104 3.1 Pointer and Memory...............................................................105 3.2 Pointer Expressions and Arithmetic........................................110 3.3 Pointer and Arrays...................................................................113 3.4 Pointers and Structures...........................................................1254 Hands-on-Pointers: Advanced Features............144 4.1 Pointers and Functions...........................................................145 4.2 Command Line Arguments: Arguments to Main.................153 4.3 File System Basics and the File Pointer .................................162 4.4 Dynamic Memory Management in C and Linked List...........1705 From C to C++......................................................181 5.1 A Brief Overview of C++ Main Features...............................182 5.2 Usage of Some C++ Key Concepts........................................184INDEX..........................................................................205
內容試閱:
IntroductionNowadays, learning a programming language becomes essential to the engineering or science education, as computation is at the core of all modern engineering and science disciplines. Furthermore, as we also believe in the Digital Technology and AI Era, we postulate that “Nowadays, learning a programming language becomes essential to ALL THE STUDENT, even kids”. Empowered with programming skills, students will also improve unique and es?sential problem-solving strategies which are easily transferable to other endeavors. This book approaches a student-centered C programming teaching and learning, by radically deviating from the classical introductory programming book’ organization, writing and content commu?nication as a tutorial. Instead, it covers C language programming how and what as well as the entire life cycle of a C program based on real details of implementation and application, while promoting and mastering debugging skills as the driver or enabler of the C programming pro?cess. Leveraging the debugging process at the core of the C programming learning and teach?ing process will avoid costly future maintenance issues alongside learning autonomy. Mainly, it promotes learners’ attitude and spirit towards lifelong learning through learning by doing, as well as by discovering and exploring the how of C language by themselves.Goals and AudienceC was chosen for the introduction to the programming process because it is a procedural pro?gramming language and also because we believe engineering and scientific problem-solving is inherently procedural. Additionally, there are several other reasons to choose C as the first programming language such as: 1 to master object-oriented programming concepts students should know first elementary programming concepts, 2 C++, Java and C# share in some way, foundational concepts and syntax of C, 3 C is unbeatable in terms of performance when compared with other high-level programming languages, and 4 major parts of the operating systems like Windows and Linux, including their device drivers are written in C. This book is written for students with no previous programming experience i.e., it is intended as a first course in computer programming and it follows an active and balanced teaching and learning approach for the theory and practice of programming language. It leads students in a holistic manner to ever-improving programming skills based on hands-on experiences and understand?ing the C programming environment and tools, while avoiding procrastination, enhancing learning autonomy or self-study at the maximum amount of enjoyment.Our Teaching and Learning ApproachTo really empower students with problem-solving and programming skills needed in their future workplace, their learning attitudes and spirit towards motivation, excitement, self-study and resilience, must be presented and enhanced in and after each class alongside hands-on activities. That is, computer programming is not an innate skill, and so, to really become comfortable with the mechanical process of writing and debugging code, students need to practice solving problems and writing code, while simultaneously being willing to learn, not afraid of failing and resilient enough to never give up.Therefore, a teaching strategy against passive reading should be fostered by teaching not only the concepts of the C language but also the entire life cycle of a C program, while discovering and ex-ploring the how of the main C concepts. All classes from the day one, should be based on hands-on experiences, starting first with demonstratives examples followed by exploration and discovering of the mechanism of main C concepts, as well as pinpointing and fixing program bugs. Incentives for active participation in and out of classes e.g., doing homework and classroom discussions should be promoted, mainly for students that are able to understand and discuss programs’ execution flow and decide for the best set of breakpoints during a program analysis and exploration. Weaker students should periodically receive feedback regarding their performance while being supported through scaffolding mechanisms, guided by teachers and top performance students. Key and Unique FeaturesContrary to existing introductory programming books that only lightly leverage debugger for bug pinpointing and fixing purposes, this book goes deeper and fosters reverse engineering approach to explore and understand the mechanism of C language concepts. In doing so, a huge degree of excitement and motivation will be triggered, leading students to deeper engagement in their own learning and thus, avoiding procrastination.Scope of Coverage Organization and ContentThis book is organized in five chapters, covering C programming language what and how and ending by smoothly moving from C to C++ and the object-oriented programming paradigm. Chapter 1 briefly presents an overview of C language mechanism, a C programming environment and tools, and the C program life cycle. The main focus of Chapter 2 goes to problem-solving, al?gorithm and the internal of the function concept in C. Chapter 3 introduces the basics of the pointer variable in C, as well as how does it interoperate with other C language constructs like array and expressions. Chapter 4 focuses on advanced pointers features and how they interoperate with files, functions, passing of arguments, dynamic memory allocation and dynamic data structure. Finally, the focus of Chapter 5 goes towards a brief understanding of the object-oriented programming para?digm, C++ key concepts and refactoring of a C program to C++.Acknowledgement and ThanksBesides the authors, many other people influenced this book development and final form. Maybe, the greatest influence came from students who have attended our programming courses for the past years, as they have given great feedback about what works and does not in the classroom. Hence, we specially thank the students for their feedback. We developed most, but not all, of figures in this book and thus, we would like to thank Tao Yu and Wang Yibo from Jilin University China for drawing some of them.The reviewers for this book, Prof. Carlos Couto, Prof. Rufino Andrade, Prof. Jo?o Monteiro and Prof. Liang Yanchun were very helpful in improving the manuscript, both correcting errors and clarifying the presentation.