iOS Development Training January 13 notes

Source: Internet
Author: User
Tags control characters mul

//

//

Main.c

Lessonhelloworld

//

Created by Lanouhn on 15/1/12.

Copyright (c) 2015 Lanouhn. All rights reserved.

//

Single-line Comment

Shortcut keys for single-line comments: command+/

/*

Multi-line comments

*/

Comment does not participate in the compilation of the program

Code → compile → executable file (. exe)

Reference standard input library for C language

#include <stdio.h>

The main function, the entry of the program

int main (int argc, const char * argv[]) {

Insert code here ...

printf ("Hello, world!\n");

return 0;

}

Shortcut keys

compiler shortcut keys: command+b

Compile + run: Command+r˜

Main.m

Lessonbasic

//

Created by Lanouhn on 15/1/13.

Copyright (c) 2015 Lanouhn. All rights reserved.

//

Command+z: Undo

command+alt+[or]: code moves up or down

Data type

Role

1, specify the size of the container storage

2, specify the type of data stored in the container

Classification

1, Integer: char (character type), short (shorter integer), int (integer), long (longer shape)

2, Float type: float (single-precision floating-point type), double (double-precision floating-point type)

Constants: Amount that cannot be changed during program run

INTEGER constant: 100,999,

Character constants: ' A ', ' B '

Floating-point constants: 3.14,0.01

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {

printf ("Hello, world!");

Variables: Amount that can be changed during program run

A variable is a container that can change the contents of a container.

Definition of a variable

Data type variable name = initial value

Variable Naming conventions

1, must consist of numbers, letters, underscores, and cannot start with a number

2, see the name of the idea

3, no duplicate name

4, cannot use System keyword

5, using Hump method named (Big Hump method and Small Hump method)

int applecount = 0;//(Small hump method)

int a = 0;

Short floor = 5;

int roomnumber = 432;

printf ("a\n");

printf ("Value of output a \ n");

printf ("%d\n", a);

Variables with the same data type can be separated by commas: int a = 0,applecount = 0

Char number = ' A ';

printf ("number =%c\n", number);

ASCII value (decimal number) for printing characters

printf ("number =%d\n", number);

When you break a point, you should hit the next line in the code you want to execute

Short S = 12;

printf ("i =%hd\n", s);

int i = 100;

printf ("i =%d\n", i);

Long L = 1234567890;

printf ("L =%ld\n", l);

Single precision, six digits after the decimal point is the number of significant digits

float F = 1.1235678923456789123456789;

printf ("F =%.20f\n", f);

Double, 15 digits after the decimal point is the number of significant digits

Double d = 1.123456789123456789123456789;

printf ("D =%.20f\n", d);

Print: Printing

F:function, function

int NUM1 = 1, num2 = 2;

printf ("num =%d, num =%d\n", NUM1, num2);

Enter: \ n

Tab:\t equivalent to four spaces

Percent percent:

Quotation marks: \ "

printf ("1\n23\t45%%67\" 89 ");

Format Control characters

int style = 123;

printf ("%5d\n", style);

printf ("%05d\n", style);

printf ("%-5d\n", style);

float fl = 123.12356789;

printf ("%f\n", FL);

printf ("%9f\n", FL);

printf ("%15f\n", FL);

printf ("%15.9f\n", FL);

printf ("%015.9f\n", FL);

printf ("%-015.9f\n", FL);

-: Left-justified, default right-justified

0: The number of digits is not enough to fill 0

15: Output bit width, insufficient default fill space

.9: Number of digits after the decimal point

Exchange values for two variables

int a1 = 3;

int a2 = 5;

printf ("a1 =%d\n, a2 =%d\n", a1, A2);

With a third variable exchange

int temp = 0;

temp = A1;

a1 = A2;

a2 = temp;

printf ("a1 =%d\n, a2 =%d\n", a1, A2);

Without the use of the third variable Exchange

a1 = A2-A1;

A2 = A2-A1;

a1 = A1 + A2;

printf ("a1 =%d\n, a2 =%d\n", a1, A2);

Operator

1, assignment operator: =

Assign the value to the right of the equal sign to the left of the equals sign:

int m = 1;

int n = 2;

2, arithmetic operators

Add:

int sum = 0;

sum = m + N;

Reducing:

int minus = 0;

minus = N-m;

By:

int mul = 0;

Mul = n * m;

Except:

Dividing integers, the values after the decimal point are ignored

int div = 0;

div = n/m;

printf ("div =%d\n", div);

int div1 = 3.0/2;

printf ("div =%d\n", div);

If the figure is 1.5, make sure there is at least one floating point on both sides of the division sign

Take surplus

Generally, only integers are taken out of the remainder

by divisor/divisor = quotient

The divisor cannot be zero

int rem = 0;

rem = n% m;

printf ("REM =%d\n", REM);

Self-increasing ++n, n++

n++;

++n;

equals n = n + 1;

Self-reduction

m--;

--m;

Equivalent to M = m-1;

Principle:

1,++ or--before, first +1 or-1, then the operation

2,++ or--after, first operation, then +1 or 1

/*

int j = 5;

int k = 0;

K = j + +;

K = J

j = j + 1

printf ("k =%d\n, J =%d\n", K, J);

K = ++j;

j = j + 1

K = J

printf ("k =%d\n, J =%d\n", K, J);

*/

/*

int j = 2;

int k = 3;

int c = 0;

Operator Precedence

C = j + (+ + k);

printf ("J =%d\n, k =%d\n, c =%d\n", J, K, c);

*/

/*

Compound operators

int k = 5;

int j = 0;

J + = K;//j = j + K

J-= K;//j = J-k

J *= k;//j = J * k

J/= k;//j = j/k

J%= k;//j = j% k

*/

/*

int x = 1, y = 2, z = 3;

int c = 10,k = 0;

x + = (++y);

y = x + +;

z = x/y;

c%= y;

K = ++c;

printf ("x =%d\n, y =%d\n, z =%d\n, c =%d\n, k =%d\n", x, Y, z, c,k);

*/

Expressions: With constants, variables, and operators: for example, x+1,y+1

Statement: The minimum unit of execution of a program, ending with a semicolon (;): for example: (x + 1;), (y + 1;)

To calculate the number of statements with semicolons

Input function: scanf

int g = 0;

printf ("Please enter an integer");

When SCANF is encountered, the program waits for the user to enter the console

Confirm input, need to use big return

scanf ("%d", &g);

printf ("G =%d\n", g);

Code specification:

Binocular operator left and right side to add space

Monocular operator does not need to add spaces

Add a space behind a comma

return 0;

}

iOS Development Training January 13 notes

Related Article

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.