發表文章

目前顯示的是有「Programming」標籤的文章

Mastering Pointers in C/C++: 10 Practical Coding Exercises for Beginners

If you are diving into C or C++ programming, there is one concept you simply cannot escape: Pointers . Often considered the first major hurdle for beginners, pointers are actually incredibly powerful tools that give you direct access to memory and help you write highly efficient code. Before jumping into the exercises below, if you need a quick conceptual refresher, I highly recommend checking out some classic guides such as [Pointers in C Programming: What is Pointer, Types & Examples] or an [Introduction to C Pointers]. To help you solidifying your understanding, here are 10 practical pointer exercises , complete with reference solutions. Let's code! Exercise 1: Basic Pointer Syntax Goal: Design a C program to demonstrate the foundational syntax of pointers, including pointer declaration, address-of retrieval ( & ), and dereferencing ( * ). Reference Solution: /* Pointer Basic Syntax Author: Holan */ # include <stdio.h> # include <stdlib.h> int main () ...

Code Maintenance & Programming Rules

 This guide outlines essential best practices spanning code style, architectural design, debugging, testing, performance, and portability—all aimed at reducing the long-term cognitive load of code maintenance. 🎨 1. Style Code is written for humans to read, and only incidentally for computers to execute. Variable Naming : Use descriptive names for global variables, and short names for local variables. Precision and Consistency : Use active names for functions (e.g., calculateTotal ). Above all, keep your coding style consistent throughout the project. Structure & Expressions : Use a consistent indentation and brace ( {} ) style to show program structure visually. Use the natural form for expressions. Use parentheses to make the semantics unambiguous. Break up overly complex expressions to keep them clear. Side Effects & Macros : Beware of functions with side effects. Avoid function-like macros; if unavoidable, parenthesize the macro body and arguments carefully. Magic Numbe...