Mastering C Language: Become an Excellent Programmer

Basic Knowledge

Mastering C Language: Become an Excellent Programmer

Computer Language: The language used for communication between humans and computers is called computer language.

Computer languages are divided into high-level languages and low-level languages.

High-level languages: Far from hardware.

Low-level languages: Close to hardware.

Instruction: A command for the computer to perform a certain operation, consisting of a series of binary codes.

An instruction usually consists of two parts: opcode + address code.

Opcode: Indicates the type or nature of the operation that the instruction is to perform, such as fetching data, performing addition, or outputting data.

Address code: Indicates the content of the operation object or the address of the storage unit.

Machine Language: The language used by various components of the computer to communicate with each other.

Characteristics: For the computer itself, it can only recognize binary instructions made up of 0s and 1s.

Source Program: A program written in a high-level language is called a source program.

Source Program ———— Compiler Program ———— Target Program (a program represented by binary code, which the computer only recognizes as the target program).

Compiler Program: How to convert the source program into a target program that the machine can accept. Software developers have created a series of software that can translate statements written by users in accordance with specified syntax into binary machine instructions one by one. This type of software with translation functions is called a “compiler program”.

C Source Program: A sequence of instructions constructed in C language is called a C source program.

C Language Code Writing: The process of writing C programs according to C language syntax is called C language code writing.

C Language Source Program File Name has the suffix .c, and after compilation, the generated file has the suffix .obj, and after linking, the generated file has the suffix .exe.

Program Design Generally Includes the Following Parts:

  1. Determine Data Structure

  2. Determine Algorithm

  3. Encoding

  4. Debugging the Program on the Computer

  5. Organizing and Writing Documentation

Algorithm: Refers to a definite and finite sequence of steps taken to solve a specific problem.

An algorithm should have the following five characteristics:

  1. Finiteness

  2. Certainty

  3. Feasibility

  4. Zero or more inputs

  5. One or more outputs

Algorithms can be described using various methods, the most common being pseudocode and flowcharts.

C Language is a structured language.

C Language Has Three Structures:

  1. Sequential Structure

  2. Selection Structure

  3. Loop Structure

  • While Loop

Check first, then execute. Can execute 0 times at minimum.

  • Do-While Loop

Execute first, then check. Can execute at least 1 time.

Basic Composition and Format of Simple C Language

C Language Learning Content:

Mastering C Language: Become an Excellent Programmer

C Language Learning Methods

Basic Format of C Language Program:

1. Command Line

1) The command line must start with “#” and must not end with a “;” because it is not a C language statement.

2) The filename stdio.h between a pair of double quotes is a system-provided filename that contains information about input and output functions.

2. Main Function

1) main is the name of the main function, and C language specifies that main must be used as the main function name.

2) The pair of parentheses following the main function can be empty, but this pair of parentheses cannot be omitted.

3) A C program can contain any number of functions with different names, but there must be exactly one main function.

4) The execution of a C program always starts from the main function.

Mastering C Language: Become an Excellent Programmer

3. Function Body

1) Below the main function is the function body, which always starts with “{” and ends with “}”.

2) The function body is divided into definition (description) part and executable statement part.

3) The number of executable statements is unlimited but must be placed after the definition statements.

Simple Syntax Format of C Language:

1) C statements must end with a “;”. The “;” is part of the C statement and not a separator between statements.

2) Comment symbols “/*” and “*/” must appear in pairs and cannot be nested. There should be no space between “/” and “*”.

Composition and Classification of Identifiers

What is an Identifier:

1. Composition: Composed of letters, numbers, and underscores.

2. Composition Rules: Identifiers cannot start with a “number”.

3. Characteristics:

1) Case-sensitive.

2) In C language, the computer only recognizes identifiers of up to “8” characters long (i.e., identifiers can have a maximum of 8 characters).

Classification of Identifiers:

1. Keywords

1) Those that have a predefined meaning in the system and cannot be used for other meanings (e.g., if, while, etc.).

2) There are 39 keywords in C language.

2. Predefined Identifiers

1) Those that have a defined meaning in the system but can be used for other meanings (e.g., printf, scanf, etc.).

2) It is recommended not to change predefined identifiers.

3. User-defined Identifiers

1) Identifiers defined by the user.

2) User-defined identifiers must comply with the composition rules for identifiers.

Integer Data and Real Data

Constants:

1. Definition: A quantity that remains unchanged during the program’s execution.

2. Classification:

1) Integer Constants (e.g., 123)

2) Real Constants (e.g., 12.34)

  • float

  • double

3) Character Constants (e.g., ‘a’)

4) String Constants (e.g., ‘hello’)

5) Symbolic Constants (e.g., π 3.1415926)

  • Syntax Format: #define Identifier Constant

#define PI 3.14159 (This means that wherever PI appears in the program, its value is 3.14159)

Variables:

1. Definition: A quantity whose value can change.

2. Essence: Memory storage unit.

Source: C Language Plus

Leave a Comment