搜尋此網誌

2025年7月6日星期日

The string class

The object-oriented approach (often shortened to OOP) is a way of designing and writing software by organizing code around objects rather than just functions and logic. It’s one of the most popular programming paradigms and is used in many modern languages like Java, Python, C++, and C#.

In C++: <string>
This header provides the std::string class, a more powerful and safer alternative to C-style strings.
It supports:
- Dynamic memory management
- Operator overloading (e.g., +, ==)

Dynamic memory management is the process of allocating and freeing memory at runtime, rather than at compile time. It’s essential when you don’t know in advance how much memory your program will need --- like when handling user input, working with large datasets, or building flexible data structures like linked lists or trees.

In C++, strncpy() is a legacy function inherited from the C standard library, defined in the <cstring> header. It’s used to copy a fixed number of characters from one C-style string to another. While it works in C++, it's generally recommended to use std::string for safer and more expressive string handling.

In C++, strncat() is a legacy function from the C standard library used to append a limited number of characters from one C-style string to another. It’s declared in the <cstring> header and works directly with character arrays.

semantics: the study of the meanings of words and phrases

concatenation: a series of things or events that are linked together

exhaustive: including everything possible; very careful or complete

Microsoft Copilot
www.oxfordlearnersdictionaries.com

2025年7月3日星期四

His teacher

"Fall of a year" refers to the season of autumn, especially in North America.

qualm: a feeling of doubt or worry about whether what you are doing is right

unbeknownst: without the person mentioned knowing

penmanship: ​the art of writing by hand; skill in doing this

cursive: ​(of handwriting) with the letters joined together

showboating: behavior that is intended to show people how clever, skillful, etc. you are

flute: a musical instrument of the woodwind group, like a thin pipe in shape. The player holds it to the side of his or her face and blows across a hole at one end.

memento: a thing that you keep or give to somebody to remind you or them of a person or place

slaughterhouse: a building where animals are killed for food

seep: (especially of liquids) to flow slowly and in small quantities through something or into something

unveil: to remove a cover or curtain from a painting, statue, etc. so that it can be seen in public for the first time

awe: feelings of respect and slight fear; feelings of being very impressed by something/somebody

appalled: feeling or showing horror at something unpleasant or wrong

crackle: to make short sharp sounds like something that is burning in a fire

scribble: to write something quickly and carelessly, especially because you do not have much time


Bill Gates "Source Code"

Online Dictionaries Used:

hk.dictionary.search.yahoo.com

www.oxfordlearnersdictionaries.com

2025年7月2日星期三

Tile

encaustic: a paint made from pigment mixed with melted beeswax and resin and after application fixed by heat

Stoke-on-Trent: city in England

www.merriam-webster.com/dictionary

2025年7月1日星期二

C strings

consecutive: following one after another in a continuous series

The null character --- written as '\0' in C and C++ --- is a special character used to mark the end of a string in many programming languages, especially those influenced by C.

<cstring> Header in C++

This is part of the C++ Standard Library, inherited from C’s <string.h>. It provides functions for manipulating C-style strings (null-terminated character arrays).

The String class is a fundamental part of many programming languages, used to represent and manipulate sequences of characters.

std::string greeting = "Hello";
greeting += " World";
std::cout << greeting;  // Output: Hello World

size_t is a special unsigned integer type used in C and C++ to represent the size of objects in memory or array indices.

An unsigned integer is a whole number data type that can only represent non-negative values—that is, zero and positive numbers.

A character array is a data structure used to store a sequence of characters --- essentially, it's how many programming languages represent strings under the hood.

ASCII stands for American Standard Code for Information Interchange. It’s a character encoding standard that assigns numeric values to letters, digits, punctuation marks, and control characters so computers can store and exchange text reliably.

In C++, strncpy() is a function from the C standard library (inherited via <cstring>) used to copy a fixed number of characters from one C-style string to another. It's a bit of a double-edged sword --- powerful but easy to misuse if you're not careful.

The sizeof operator in C and C++ is used to determine the size, in bytes, of a data type or object at compile time.

strncpy(name, src, sizeof(name) - 1);
name[5] = '\0';  // Manually null-terminate

Here, the -1 is used because:
You reserve the last slot for the null terminator.
You copy at most n - 1 characters to avoid overflow.
Then manually add '\0' at the end.

concatenate: to link together in a series or chain

The strcat() function in C is used to concatenate two C-style strings—that is, it appends one string to the end of another.

The strncat() function in C is used to safely concatenate a limited number of characters from one C-style string to another.

In C++, strlen() is a function from the C standard library (accessible via <cstring>) that returns the length of a null-terminated C-style string, excluding the null character '\0'.

Microsoft Copilot
www.oxfordlearnersdictionaries.com
www.merriam-webster.com

Top seller

dog-eared: (of a book) used so much that the corners of many of the pages are turned down

distillation: (formal) the process or result of getting the essential meaning, ideas or information from something

advancement: progress in a job, social class, etc.

boot camp: a training camp for new members of the armed forces, where they have to work hard

filbert: a type of hazel tree that produces oval nuts

pecan: the nut of the American pecan tree with a smooth pink-brown shell

daunting: making somebody feel nervous and less confident about doing something; likely to make somebody feel this way

tally: a record of the number or amount of something, especially one that you can keep adding to

parameter: ​something that decides or limits the way in which something can be done

pistol: a small gun that you can hold and fire with one hand

If you say that a person, a team, an organization, etc. has bragging rights, you mean that they have achieved a good result or are better or more successful than their competitors or opponents at that time.

steep: sudden and very big

pitch: to set something at a particular level

hash mark: service stripe

service stripe: a stripe worn on an enlisted person's left sleeve to indicate three years of service in the army or four years in the navy

perennial: ​continuing for a very long time; happening again and again


Bill Gates "Source Code"

Online Dictionaries Used:

hk.dictionary.search.yahoo.com

www.oxfordlearnersdictionaries.com

www.merriam-webster.com

2025年6月29日星期日

Reference & in C++

In C++, a reference is essentially an alias for another variable. Once a reference is initialized to a variable, it becomes just another name for that variable—any operation on the reference is actually performed on the original variable.

- Declared using the & symbol

int a = 10;
int& ref = a;  // ref is a reference to a

- Must be initialized when declared.
- Cannot be changed to refer to another variable after initialization.
- Useful for function arguments and return values to avoid copying large data.

Reference:
int& ref = var;
cannot be null
cannot be reassigned
do not need dereferencing

Pointer:
int* ptr = &var;
can be null
can point to difference variables
need dereferencing

In programming, an alias is a second name for the same memory location. It means two or more variables refer to the same underlying data—so changing one affects the other.

Modifying a reference does change the original variable, because they both refer to the same memory location.

In programming, nullability refers to whether a variable is allowed to hold a null value --- meaning it can represent the absence of a value.

syntax: (computing) the rules that state how words and phrases must be used in a computer language

In C++, a reference is essentially an alias for another variable. That means:
- It doesn't exist as a separate object in memory.
- When you take the address of a reference, you're actually getting the address of the original variable it refers to.

C++ does not allow arrays of references.

References are not objects: They don’t occupy their own memory --- they’re just aliases for existing variables.

Arrays require elements to be assignable: But references must be initialized when declared and cannot be reseated.

References must be initialized at declaration.

A reference is not a standalone object; it must alias an existing variable.
Because of this, the compiler needs to know what it's referring to immediately --- there is no such thing as a "null" or "unbound" reference.

In C++, pointer initialization is optional, but that comes with a big caveat.

caveat: a warning that particular things need to be considered before something can be done

In C++, references provide one level of indirection.

indirection: indirect action or procedure

In C++, multiple levels of indirection with pointers means having pointers that point to other pointers --- and this can go as deep as your brain (or compiler) can handle!

When you use a reference:
- You're not accessing the object directly.
- Instead, you're accessing it through an alias --- a single level removed from the actual object.

In C++, you can absolutely declare a pointer with the void type, and it's known as a void pointer or generic pointer.

A void* is a special type of pointer that can point to any data type, but it doesn't know what type it's pointing to.

References in C++ are like secret passageways --- they let you access and manipulate data efficiently without the overhead of copying.

iteration: the process of repeating a mathematical or computing process or set of instructions again and again, each time applying it to the result of the previous stage

Microsoft Copilot
www.oxfordlearnersdictionaries.com

2025年6月27日星期五

Reading

congregational: connected with the group of people who belong to a particular church and go there regularly

parishioner: a person living in a parish, especially one who goes to church regularly

by dint of something/of doing something: by means of something

charisma: the powerful personal quality that some people have to attract and impress other people

meld: to combine with something else; to make something combine with something else

The Sermon on the Mount is a collection of sayings spoken by Jesus of Nazareth found in the Gospel of Matthew that emphasizes his moral teachings.

The Old English Sheepdog is a large breed of dog that emerged in England from early types of herding dog.

scavenge: (of a person, an animal or a bird) to search through waste for things that can be used or eaten

meander: to bend with curves rather than being in a straight line

slick: having a smooth surface

neat: tidy and in order; carefully done or arranged

Adélie penguin: a gregarious territorial penguin of Antarctica, having a distinctive white ring around the eye

intricate: having a lot of different parts and small details that fit together

trellis: an arrangement that forms or gives the effect of a lattice

lattice: a structure that is made of thin, narrow pieces of wood or metal that cross over each other with spaces that are like diamonds in shape between them, used, for example, as a fence; any structure or pattern like this

sturdy: ​(of an object) strong and not easily damaged

generalization: a general statement that is based on only a few facts or examples; the act of making such statements

clique: a small group of people who spend their time together and do not allow others to join them

baffle: to confuse somebody completely; to be too difficult or strange for somebody to understand or explain

maddening: ​making you feel extremely annoyed

worrisome: that makes you worry


Bill Gates "Source Code"

Online Dictionaries Used:

hk.dictionary.search.yahoo.com

www.oxfordlearnersdictionaries.com

www.merriam-webster.com