iOS basic operations

Source: Internet
Author: User
<span id="Label3"></p><p>//<br>Main.m//file Name<br>Day2-class//project Name<br>//<br>Created by open on 16/1/5.//date created and created by<br><br>//<br>Single-line Comment: can annotate a piece of code, play the role of explanation, note is the embodiment of our Programmer's programming thinking, Note does not participate in the program Run.<br><br><br>/*<br>This is a multi-line comment.<br>Comd+z: Undo<br>Comd+,: Set<br>Comd+a: Select All<br>Comd+shift+n: Create a new project<br>Comd+[: Let our lines of code move left<br>Comd+]: Let our lines of code move right<br><br>*/<br><br><br>#import: Import<br>#import <>: represents the framework in which our systems are imported (that is, the foundation Framework)<br>#import "": represents the import of files we create ourselves<br><br>#import <Foundation/Foundation.h><br><br><br>Function: it is by function type function name (parameter---> formal parameter, argument)<br>{function body; }<br>VOID stands for none, no return value is required<br>Function: it encapsulates a piece of code snippet<br>void Test ()<br>{<br><br><br>}<br><br><br>Main Function: He is the entrance to our program, The program starts execution, it encounters a return end, the code snippet is written in return 0;<br>int main (int argc, const char * Argv[]) {<br><br><br>@autoreleasepool: It's The syntax of our oc, called the Auto-release Pool.<br>@autoreleasepool {<br>Insert code here ...<br>NSLog (@ ""); This is also the print function in our OC<br>NSLog (@ "Hello, world!");<br>//    }<br><br>Data type:<br>Format: type modifier variable name = value;<br>Semicolon (;): A concluding sentence representing our code snippet<br>int NMU = 7;<br>Float type only outputs 6 decimal places by default<br><br>FLOAT score = 88888.923456;<br>printf ("%f\n", score);<br>%f output only 6 decimal places by default<br>printf ("%.7f\n", score);//represents a seven decimal place after the output decimal point<br>%f after printing, float precision is 6 digits after the decimal point, but the valid number is 7 bits<br>? Then we want to print out 3.1415926 what to do<br>The number of valid digits for a double is 15 bits<br>Double D1 = 3.1415926;<br>printf ("%.7lf\n", d1);<br><br>If you want to output 7 bits then we can use double<br>/*<br><br>Float Type: The significant number of digits is 6 bits<br>Double type: the number of significant digits is 15 bits<br> <br>*/<br>Character Type:<br>Character type format: type modifier variable name = ' ' (single quote);<br>Spaces also represent a character<br>char sex = ' m ';<br>Constant: The amount of time that cannot be changed while the program is running<br>Variable: is the amount of time that can be changed while our program is running<br>A variable is equivalent to a piece of storage space in our memory = number is an assignment operator<br>Variable naming rules:<br>1. can only be composed of numbers, letters, underscores, $, cannot start with a number;<br>2. cannot have the same name as the system reserved word;<br>3. Duplicate variable names cannot be used;<br>4. See the meaning of the name;<br>5. The Hump method is named;<br>#pragma mark--operator---quick Index<br>#pragma mark (hint Word) is a quick index<br><br><br>The first (must be mastered) (hand-copied 10)<br>int NUM1 = 21;<br>int num2 = 25;<br>Then we define a Third-party variable to store the value we exchange.<br>int temp = 0;<br>Give the value of NMU1 to Temp<br>temp = num1;<br>Give the value of num2 to NUM1<br>NUM1 = num2;<br>Give the value of temp to num2<br>num2 = temp;<br>printf ("num1 =%d", num1);<br>printf ("num2 =%d", num2);<br><br><br>The second type:<br>You do not need to use additional variables to swap with ADD and subtract<br>Define two variables of type int<br>/* int num3 = 34;<br>int num4 = 43;<br>num3= num3 + num4;<br>num4= num3-num4;//(num3 + num4)-num4<br>num3= num3-num4;//(num3 + num4)-num4<br>printf ("num3 =%d\n", num3);<br>printf ("num4 =%d\n", num4);<br><br>Third Kind<br>Use XOR or (^);<br>int a =3,b = 4;//the same data type can be placed in the same rowset named<br>A = a^b;<br>b = a^b;<br>A = a^b;<br>printf ("a =%d\n", a);<br>printf ("b =%d\n", b);<br><br><br>*/<br><br>//+,-,*,/<br>A variable of type int is defined as an initial value of 5;<br>int a = 5;<br>A variable b that defines an int type has an initial value of 10;<br>int B = 10;<br>Define a Third-party variable to receive our A and B's and<br>int result = 0;<br>result = A + b;<br>printf ("result =%d\n", result);<br><br>-; subtraction;<br>int c = 10;<br>int d = 5;<br>int JF = 0;<br>JF = c-d;<br>printf ("JF =%d\n", jf);<br><br>Multiplication (division)<br><br>self-increment, self-reduction<br>+ + in front, the first to +1, and then participate in the operation,<br>+ + in the after, the first operation and then to self +1<br>//<br>int a = 2;<br>int B = 4;<br>int c = 0;<br>c = a+++b++;//c = (a++) + (b++);<br>printf ("%d\n", c);<br><br>Char: occupies one byte, range -128~127<br><br>Char type constant storage, which corresponds to the corresponding ASCII code table value corresponding to the storage<br>char a = ' a ';<br>printf ("%d\n", a);//our Corresponding character can be occupied with%d, but we will print the value of our corresponding ASCII code TABLE.<br>//<br><br>#pragma mark--composite operator--<br>// += -= *= /=<br>int a = 4;<br>int c = 0;<br>c + = a; c = c+a;<br>c = 0+4;<br>printf ("%d\n", c);<br>int B = 6;<br>int d = 7;<br>int e = 0;<br>e-=b;//<br>printf ("%d\n", e);<br>//    //*=<br>E *= d;//e = e*d<br>printf ("%d\n", e);<br><br>#pragma mark---printf---<br><br>printf ()//formatted output function<br>scanf () Format input function (blocking Function)<br><br>/*<br>***********<br>hello***<br>***********<br>*/<br>printf ("***********\n***hello***\n***********\n");<br>To define a variable of type int and assign an initial value of 18 to it, and print<br>int age = 18;<br>printf ("age=%d\n", age);<br>printf ("*\n * *\n* * *\n");<br>Scanf: Blocking function;<br>int age1 = 0;//is assigned a value of 0, in order to clear the data<br>printf ("please Enter an age: \ n");<br>Scanf: executes when a newline (carriage Return) is encountered<br>1. Receive the value of a single variable, if we enter a carriage return or tab will be ignored before entering<br>//<br>scanf ("%d", &age1);//& It is a fetch address character, the function is: the data entered by our user is stored in our corresponding variable<br>printf ("age1=%d\n", age1);<br><br>Please enter two numbers and sum<br>int NUM1 = 0;<br>int num2 = 0;<br>int sum = 0;<br>printf ("please enter two numbers: \ n");<br>scanf ("%d%d", &num1,&num2);//note: The address (&) when the "%d%d" do not add anything (for example, \ n), Otherwise the output is not correct, plus (\ N) For example (%d\n%d\n) will be offset (\ n); (,) For example (%d,%d) must be entered (,) otherwise only the value of NUM1 is Output.<br>scanf ("%d", &num1);<br>scanf ("%d", &num2);<br>sum = num1+num2;<br>printf ("sum =%d\n", sum);<br>/*<br>scanf use Note:<br>1. In our scanf input function do not add \ n, because \ n will offset the carriage return, if you want to continue to make the program execution, then in the console input a string of English (random input), will continue to offset<br>2. We scanf function in the user input, according to "", some internal symbols to enter (that is, what to enter What)<br>3. The best thing to do is to add nothing (the direct placeholder is Ok)<br><br>*/<br>#pragma mark--memory buffers--<br>int a =2, B = 3;<br>char C = ' 0 ';<br>printf ("please Enter the corresponding data type: \ n");<br>scanf ("%d%c%d", &a,&c,&b);<br>printf ("a=%d\nc=%c\nb=%d", a,c,b);<br><br>Format Control for Output:<br>/*<br>%2d:2 indicates the width of the output, less than two bits, the first fill the space, and the output is aligned<br>%02d:0 representative, less than 2, when the first 0<br>%-4d:-represents that the content of the output is left justified<br>*/<br><br><br>int age = 9;<br>printf ("%d\n", age);<br>printf ("%2d\n", age);<br>printf ("%02d\n", age);<br>printf ("%-4d\n", age);<br><br><br> <br><br><br><br><br><br>Encounter return 0; End<br>Return 0;<br><br><br>}<br><br></p><p><p>iOS basic operations</p></p></span>

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.