Stage C [01] and [01]
I. hexadecimal
Carry method: returns the result of a number-in-number (that is, a number-in-number)
Example: decimal 12; binary 0b (Computer prefix) 0b1011; octal 0 073; hexadecimal 0x 0 xABCDEF
Convert decimal (X) to other hexadecimal (Y) Methods: returns the remainder of the Division. Divide X by Y to sort the obtained remainder.
Other hexadecimal decimal: polynomial summation. The sum of the power of each number in the Multi-hexadecimal number (several-1) is obtained.
An octal can be converted to three binary bits; a hexadecimal can be converted to four binary bits.
The octal and hexadecimal formats are used to conveniently represent binary.
2. Annotations: single-line annotations (//) and multi-line annotations (/**/)
Comments: comments are intended for programmers to explain and describe the role of code. They do not participate in execution during program running, which is equivalent to a space.
The content of a single line comment can only be written behind //, but cannot use enter to wrap the line.
/*
You can use enter in multi-line comments.
Single-row comments can be nested in multi-row comments, but multi-row comments cannot be nested in multi-row comments.
// Single line comment
Multiple lines of comment can appear in a single line comment, but enter cannot appear in multiple lines of comment.
*/3. General form of simple programs
1 #import <Foundation/Foundation.h>2 3 int main (int argc, const char *argv[]) {4 5 return 0;6 }
# Import the system framework;
<Foundation/Foundation. h> framework provided by the system. Header file of the Foundation. h system. The header file is equivalent to a manual, which is used to introduce the system framework <> and the custom framework "".
Int main (int argc, const char * argv []) is the main function, which is the entry of the program. A main function is required for execution of any program, and only one main function can be used for a function;
Data Type returned by the int function; main function name; int argc, const char * argv [] function parameters.
Return 0 indicates the return value of the main function. return 0 indicates that the main function is normally output. Other numbers indicate that the function is abnormal.
Iv. Data Types
C language data type ( Purpose: To properly utilize the memory space, Specify the size of the data to be stored in the memory) |
Basic Data Type |
Integer |
Short |
2 bytes |
% Hd |
Int |
4 bytes |
% D |
Long |
4/8 bytes |
% Ld |
Floating Point Type |
Float (single precision) |
4 bytes |
% F |
Double (double) |
8 bytes |
% Lf |
Character Type |
Char |
1 byte |
'C'; '1': each character represents an integer in the ASCII table. |
Construct Data Types |
Array, struct |
|
Pointer Data Type |
Address |
String "hello"; "en" |
Null type |
Void |
|
Define a variable: data type variable name = initial value;
Int age (Value assignment operator) 21;
Functions of variable constant variable naming rule Initialization
Constant: the amount of data that cannot be changed during the entire running process of the program;
Variable: the amount of data that can be changed during the running process of the program. The variable represents a storage area in the memory, and the value of the storage area can be changed.
When using a variable, you must first consider the size of the data type to be stored in the memory (that is, the amount of bytes ).
How to Use variables: 01. Determine the data type; 02. Determine the variable name; 03. initialize the variable.
A constant is used to assign values to a variable.
Variable naming rules: 1. it can only consist of numbers, letters, underscores, and $ (dollar sign), and cannot start with a number. 2. it cannot be the same as the system keyword. There are 32 system keywords. 3. repeated variable names cannot be used (Redefinition of 'age', which indicates repeated variable names 'age'); 4. see the name and description.
The purpose of initialization is to prevent the use of the number of Spam left in the memory of the last time, assign the initial value v. Output Function <printf>
1 float a = 3.14; 2 printf ("a = %. 2f \ n", a); 3 // %. nf indicates the output of n digits after the decimal point
% Md
① When m is negative, it is left aligned. If | m |> the number of digits of the current number, fill in spaces on the right side; otherwise, the output is normal.
② When m is a positive number, it is right aligned. If | m |> the number of digits of the current number, fill in spaces on the left side; otherwise, the output is normal.
Vi. Operators