iOS Development Learning Note 001

Source: Internet
Author: User
Tags function prototype

First to learn the basic knowledge of C language, summarized as follows:

Write the code under Xcode.

1. Write code

2, compile: Cc–c file name. C

Successful compilation will generate a. O target file

3, Link: The target file. O and the library that comes with the system are combined to generate an executable file.

directive: CC file name. O

A successful link generates an. Out executable file, which is selected to run with a terminal.

4. Run:./a.out//You can also double-click A.out to run

  ./indicates the current path

You can also compile and link

directive: CC A.C

can generate files directly in the terminal, generate a source file to the current directory

directive: Touch A.C

Then open it directly in the terminal, open the file in the current directory

directive: Open A.C

Multiple files can be compiled at the same time, separated by spaces

directive: Cc–c A.C B.C D.C

C language

Precautions:

Note the coding style.

Key words:

32 keywords, all lowercase

 Auto double int struct break else long switch

Case enum Register typedef char extern return Union

const float Short unsigned continue for signed void

Default goto sizeof volatile do if and static

Identifier

Customize some of the symbols and names. cannot be duplicate with keyword.

Naming rules

1, Composition: 26 English letters, 10 digital 0~9, Underline _

2. Strictly case-sensitive

3. Cannot start with a number

4. Keywords cannot be used as identifiers

Comments

Explain the meaning of a line of code. The position is not fixed. But it's best to put a line in the code or behind the bank. The comment code does not participate in compilation.

Single-line Comment://single-line comment

Multi-line Comment:/* Multiline Comment

Multi-line Comment */

Data

static data and Dynamic Data

Static data: In the hard disk, and the computer to open the machine Independent

Dynamic Data: In memory, all data is lost after the computer shuts down

Data type

Constant

Integer constant (1,3445), floating-point constant (double,float) character constant (' a ', ' B '), string constant ("Asdfadsfas")

Variable

The amount of time that has been changed during use can be represented by a variable

Definition mode: Variable type variable name;

int score;//Definition

Score = 100;//Assignment

scanf function to get user input

int age;

scanf ("%d", &age);

The scanf function waits for the user's keyboard input and does not execute the code backwards. The 1th parameter of scanf is "%d", stating that the user is required to enter an integer in 10 binary form. Note here that the 2nd argument of scanf is not the age variable, but the address of the age variable &age,& is an address operator in the C language that can be used to get the address of the variable.

printf function, output data

printf ("%d", age);

The function prototype is extern void printf (const char *format,...); Multiple parameters can be accepted.

For example

1     int I, J; 2     scanf ("%d,%d", &i, &j); 3     printf ("i=%d;j=%d", I, j);//multiple parameters, output multiple values

Scope of the variable

Start with the defined sentence until the end of the code block.

A code block is all the code inside a curly brace. The scope of a variable defined inside a code block is inside that code block.

1 intMain ()2 {3      intScore = -;4      {5            intScore = $; 6printf"%d", score);//output is7       }8printf ("%d", score);//output is 100
9 }

Local variables (variables defined inside the function) and global variables (variables defined outside the function)

Local variables inside the function override global variables.

Memory address

The memory address is contiguous, in bytes.

Variable

Bytes

Char

1
Int 4
Float 4
Double 8

 Variable memory address allocation, memory addressing from large to small, so the first defined address value is larger.

int a=10;

printf ("A's address is:%p", &a),//%p used to output address,& used to take the variable address

2015-4-8, today, tomorrow remains.

iOS Development Learning Note 001

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.