C-Language summary

Source: Internet
Author: User

The suffix. c file is the source file for the C program  1. New file   Terminal--CD path->touch main.c2. cc-c main.c, compiled file terminal, generates MAIN.O files binary code for. c Files 3. CC MAIN.O, which generates a startup file terminal, generates a a.out file, which is a program that can eventually be executed 4. Execute a.out Program Terminal---/a.out to execute program content  xcode compiler command + R compile Run command + B compile command +,   set  text Editiong, line numbers   Create multiple target + under Project nbsp; Click on the project name, click on the left expand, click on the below + to create a new target, you can also file->new target. After running the button, you can select the default startup Project   #include <stdio.h>// Import the system's stdio.h header file int main () {///define main function return value to int    printf ("Output");    return 0;} The main function is the entry of the program, a standard C program can only have one main function   Comment Line//multi-line */*/shortcut key COMMAND +/  variable is stored in memory data. Variable name, variable value. Data type: int integer, float single-precision floating-point, double double-precision floating-point type, char character type, variable name of variable data type, variable name = value for variable assignment;  int a = 1; float f1 = 12.12f; Double D2 = 12.12; char c = ' C ';p rintf ("%f", F1), float can only hold 7 decimal places, if more than 7 bits are not accurately saved. The  double is 16 bits. Char can only hold single characters, use single quotes, if write two then save last c= ' CV ' output v  output variable value printf ("Format control", variable name) int        %dfloat     %fdouble%lfchar &NBsp  %cprintf ("%d%f%c", a,b,c);  If a variable is not assigned a value, the value is random.   Format shortcut key check code Command + [left] right  printf function using 1.printf ("Output Information"); 2.printf ("%d", number); Output variable 3.printf ("%5d", number); Output a 5-bit integer, and if less than 5 bits will be padded with spaces. Larger than 5 bits are displayed. 4.printf ("%04d,number");//output 4-bit integers, if not sufficient, will be 0-padded. 5.printf ("%lf", double);//If double more than 6 bits is not displayed. 6.printf ("%.2lf", double);//output double 2-bit, 7-bit 8-bit yes. 7.printf ("%.2f", float);//Output 2-bit float  delete the target in the project, the left management bar needs to be deleted, click on the project targets also to be deleted, above the start Item Management Schemmes Click-Number Delete. All three of them have to be deleted   data type conversion      when int A; a=2.5; Output 2 is automatically intercepted.      double d = 1; Output 1.000000 Auto plus 0    char c = 97; Output A for char can be directly assigned the ASCII code   ' A ' =65 ' a ' =97 ' 0 ' =48 scanf function to get user input  int num;scanf ("%d", &num); Use the & symbol to get the variable address   custom connector scanf ("%d-%d-%lf", &num1,&num2,&double3)   input 12-23-3.3   Buffer for the SCANF function 1. After the SCANF function has entered data, the data is stored in the buffer. 2. When executing the scanf function, the buffer is checked for data, and if there is no data in the buffer, the user is entered, and if there is data in the buffer, the data is fetched from the buffer. scanf ("%d", NUM1); scanf ("%d", num2); If you enter the first num, enter 10 spaces 20 return to the car the second without input directly take out 20rewinD (stdin); Emptying the buffer, otherwise unable to enter a carriage return char will assume that the carriage return is a space output   swap two variables for the value 1. With third-party variables temp = NUM1; NUM1 = num2; num2 = temp;2. Two number add and subtract NUM1 = Num1 + num2; num2 = num1-num2; NUM1 = num1-num2;  arithmetic operator + Plus, minus, * multiply,/divide,% remainder arithmetic expressions are linked by arithmetic operators, called arithmetic expressions.   arithmetic operator precedence is multiplication, plus minus. Operation from left to right. Parentheses can change the precedence of char types can also participate in operations, according to ASCII number arithmetic   compound assignment operator + = =/= *=%=  self-increment auto-decrement operator ++-++num; First + + calculation after the operation num++; after + + first operation ++  comma expression expression 1, expression 2, expression 3, ... An expression of N. Executes from start to finish, and the result of the last expression is the result of the entire comma expression.   comparison operator > greater than < less than >= is greater than or equal to <= less than equals = = equals = = does not equal    use int type data in C language to represent true or FALSE, 0 for false non 0 for real.   logical operators && and | | or! Non-priority! && | | &NBSP;IF Branching structure  if (true) {}elseif (true) {} else{}  variable scope int num = 1;  if (num>0) {    int  age=10; }//after the execution of the program in curly braces, the variables inside the curly braces are immediately recycled.  //can not use age in this, because it has been recycled. can only be accessed from above. You can use Num.   ternary expression int num = 2>1? 1:2   random number # include <stdlib.h>//Introduction System header File Call Arc4random_uniform (10); Generates a random number of 0-9  switch syntax switch (RAND) {    case 1:    case 2:       //1 and 2 are all executed         Break;    default:         break;} Xcode shortcut command+0 Hide/Show left command+option+0 hide/show right command+12345 toggle Show left Item Menu option+ left click into U-file code split screen command+shift+f Quick Search Item Command+shift+o definition of direct search code command+r run command+b compile command+shift+0 Reference document   Debug Click on the line number to set the breakpoint, cancel the breakpoint and hold it to the right. Stop over F7 f8  Loop while first judgment after execution Do-while first execute after judgment for fixed number of loops  break; stop continue jump out of this time to continue next   Goto Jump Statement jumps The current statement to another place in the current function to continue to the Goto Labelname;labelname: Write the tag name where you want to jump. The   function uses functions to implement code reuse. return value type function name ([parameter list]) {   //code block}viod test () {}  if you want to use a document comment for a method you need to install the plugin vvdocumenter  variable scope: local variable:    Defines the variables inside the function that are used within the function.      If no assignment value is garbage value. Global variable:    defines a variable outside the function that is used for the global.     General global variables are defined under # include, if no value is 0.   parameter void test (int num); Formal parameters: A function that declares a function is called a formal parameter. Test (1); Arguments: values that are actually assigned to the parameter when the function is called   return type int getsum (int num1,int num2); return immediately ends the execution of this function, returning data based on the return type. The   function definition needs to be defined above, because the compiler executes the code from top to bottom when it is compiled.The   preprocessing code executes before compiling, beginning with the # number. The file contains directives: #include     can copy the contents of the file to the place where the written instruction is made.     #include "file path"//For custom     #include < file path >//For the system comes with: main () {#include   "/users/ David/desktop/test.txt "//Copy the text content to this}  relative path, absolute path.   Multi-file development 1. When a. c file is added, if the function is written in another file, the function needs to be declared first. int getsum (int num1,int num2);  //other files implemented  main () {    getsum (in);} 2. Add a new. h header file, and write the declaration of the function in this file. When other files use functions, include the header file first, then you can use the function.   Judgment is not even if (num & 1) = = 0) The value of the even exchange two variables a = a ^ BB = a ^ BA = a ^ b  a counting way, the focus is on the number of times the count is sealed into one. The C language can recognize binary binary, octal, decimal, hexadecimal.   binary: Every two in one, each digit is represented by 0 or 1. 0 1 10 11 100 101 110 111 1000 Write a binary in the C language that requires a prefix of 0b in front.   Octal: Every eight in one, each can only be 0 1 2 3 4 5 6 70 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 20 21 22 in the C language to write an octal, you need to precede a 0 prefix. %o, the integer data is output in octal.   Decimal: Every ten in one, each 0 1 2 3 4 5 6 7 8 9 write an integer directly in the C language, and the default is decimal. %d, the integer data is output in decimal.   16 binary: Every 16 in one, each bit 0 1 2 3 4 5 6 7 8 9 a b c D e f  write a hexadecimal in the C language, you need to prefix the front with a 0x. %x, the integer data is output in hexadecimal.   Decimal to binary, except 2, until the remainder is 0 or 1, and thenThe remainder of the reverse is the decimal corresponding binary binary binary to decimal, weighted method, the binary digital each bit of the right to add, that is, the corresponding decimal decimal to octal system, in addition to 8 take the remainder method, until 0 or 1, is the corresponding octal octal to decimal, weighted method, The octet of each digit of the right to add, that is, the corresponding decimal   memory of the data storage Unit is composed of a bits, each bits can only store 0 or 1. Divides 8 binary into 1 groups, called 1 bytes, as the smallest basic unit for storing data. So as long as you want to store data in memory, you need to save at least one byte of data, that is, 8 binary data. 8bit = 1byte1024 byte = 1kb1024kb = 1MB1024MB = 1gb1024gb = 1tb int 4 bytes Double 8 bytes Float 4 bytes Char 1 bytes  sizeof operator sizeof (data type | variable name | constant) returns the number of bytes that this data type variable occupies in memory. sizeof variable name constants can be no parentheses   array int arr[5]; Declaration declaration must be filled with a length can be a constant, variable, expression, etc. arr[0] = 100; Do not exceed the subscript write 5Int arr1[3] = {n/a}; Declares and initializes an array of int arr2[2] = {0}; Initialize all values to 0Int ccc[] = {The array name in the 1,2,3,4,5,6} c language stores the address of the array, so you cannot print the array name directly, so that the value of the element in the array is not reached. So use%p to print the array name.   The length of the array sizeof (ARR)/sizeof (arr[0])//Calculate the total number of bytes occupied by the array divided by the number of bytes per element   value passed: Int, float,double as the parameter does not change the original value   Reference passing: The array as a function parameter, changing the original value, when passed is the real parameter group address void test (int arr[],int len) {    for (Int i =0;i<len;i++) {         arr[i]=100;   }}main () {    int shuzu[] = {110,1,2};  & nbsp test (shuzu,sizeof (Shuzu)/sizeof (shuzu[0]));  } //array inversion int arr[] = {10,23,34,23,5,6,45,7,45,34,8,100 }int len = Sizeoff (arr)/sizeof (arr[0]); for (Int I = 0;i<len/2;i++) {    int temp = arr[i];    Arr[i] = arr[len-1-i];    Arr[len-1-i] = temp; Swap the No. 0 and 12th}  two-dimensional array in memory creates a specified row, a table of the specified column to store the data declaration two-dimensional array data type array name "Number of rows" "Number of Columns" assignment arr[0][0] = 100;  Declaration and Assignment int arr[][4] =  {    {10,20,30,40},    {11,21,31,41}//automatically confirms the number of rows}  string in the C language, a character array is used to store string data. "Jack" = ' j ' A ' a ', ' C ', ' k ', ' "\" means the end of the string store. Char name[] = {"Jack"} Auto-add length 5char name[] = "Jack"%s output string   Determine string length while (Name[len]! = ' + ')  len++;  string Common letter Number: puts (): Output string. Gets (): Receives 1 String Data strlen (): Returns string length strcmp (): Compare String strcpy (): Copy to another string strcat (): Connection string   The address of the pointer variable is called the pointer   

C Language Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.