Phper learns c's notes. References learn C on the mac
Book address-http://pan.baidu.com/s/1eQBW2hO
Source Code address -- http://pan.baidu.com/s/1eQGGkE2
1. I will not talk about the simple creation. Let's start with the most basic hello word.
// Import the file
# Include <stdio. h>
// Main Function
Int main (int argc, const char * argv [])
{
// Output, end line feed, and finally return 0
Printf ("Hello, World! \ N ");
Return 0;
}
Spline + R run code output result.
Compile and run the code from the terminal.
Cd into the root directory, we use gcc to compile-o to specify the file name. The above file name is main. c, so
Gcc-o main. out main. c
Ls. Well, do you still remember to compile and install php on linux? So./main. out to run the file and output Hello, Word!
Good luck is finished.
---------- What is the purpose? Well, we used to regularly execute a script. For example, at, we imported the newly added data into solr. It turned out to be a php script executed with crontab ,, now you can execute a compiled c to solve the problem that php cannot solve.
2. function declaration. Let's look at the following code.
# Include <stdio. h>
Void SayHello (void );
Int main (int argc, const char * argv []) {
SayHello ();
Return 0 ;}
Void SayHello (void ){
Printf ("Hello, world! \ N ");
}
Void SayHello: Unless you write it on int main, you must first declare it when using it. This is true for python, java, and Objective-C. Except for the scripting language, js and php are not restricted.
3. Next we will talk about 1 byte = 8bit. One bit can only store 0 or 1. Therefore, 1 byte = the power of 2, that is, 128 numbers can be stored between 0 and.
Then we will talk about ++ --.
Int I = 2, j;
J = ++ I; j is equal to 3. It is hard to understand that j = I ++; j is equal to 2; I is equal to 3, while ++ has a higher priority than =.
There is a symbolic priority icon in the book. I will not talk about it here.
3, printf ("Looping: % d \ n", I);, % d output I value, % d is an integer type, similar
% D, % I, representing integer, % f-floating point, % s, String, % c, char. % p pointer, % fL long log, % esubject count, % g decimal or scientific count
4. The following is the pointer of the God who calls the God in C language.
There are too many things to say about pointers.
# Include <stdio. h>
Int main (void ){
Int myInt;
Int *;
A = & myInt;
Scanf ("% d", & myInt );
Printf ("myInt is % d \ n", myInt );
Printf ("The myInt pointer is % p \ n", );
Printf ("using a pointer to access myInt is % d \ n", * );
}
Also,
# Include <stdio. h>
Void SquareIt (int number, int * squarePtr );
Int main (int argc, const char * argv []) {
Int square;
SquareIt (5, & square );
Printf ("5 squared is % d. \ n", square );
Return 0;
}
Void SquareIt (int number, int * squarePtr ){
* SquarePtr = number * number;
}
References in the root php are similar in usage, but references are not pointers. References in php are only aliases of variables.
5. I was impressed by the data type. There is no bool type in C. In most cases, it is represented by 1, 0 ,. C does not have the string type. You can declare the char number to assemble the string. The legal type of C can be added before the array is declared. memory usage is involved here.
6
File Operations are basically the same as php operations.
7. Chapter 5 may be the most interesting chapter in this book. It describes usage of pointers, recursive functions, recursive addition and reference, binary tree, binary tree search, and function pointers, initialization,
And create your own data types, including the above string, and bool.