C1-Basic Concepts

Source: Internet
Author: User

//

Main.m

C1_ Basic Concepts

//

Created by Dllo on 15/6/30.

Copyright (c) 2015 Zhozhicheng. All rights reserved.

//

#import <Foundation/Foundation.h>

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

int a=10; Define a variable A, which has a value of 10

int b=20;

Single-line Comment

/*

* Multi-line Comment

*/

Defining variables

First part: type modifier, int,char,float

Part II: Variable names

Part III: Setting an initial value (normative problem)

int a = 10;

float B = 3.14;

Only one character in a single quotation mark in a character type variable

char c = ' A ';

//

Naming conventions for variable names

1. Variable names consist of numbers, letters, underscores, numbers cannot begin

int d = 10;

2. Variable names can not be the same as system reserved words, system reserved words will generally have color changes

int int = 20;

3. Variable names cannot be the same, even if the type is different

int a = 20;

float a = 20.0;

4. See the meaning of the name

int studentage = 20;

Char stusex = ' W ';

float Stuscoreboyhello = 37.5;

Hump Naming method

int a = 10;

A = 100; Assigning values to a variable

The equals sign has the lowest priority, and the last assignment is performed

A = 10 * 20 + 10;

//

int B = 20;

A = b;

//

How to Exchange values for two integer variables

int a = 10;

int B = 20;

int a = ten, b=20;

Defines a temporary variable that is used for temporary storage

Temp temporary variable

int temp = 0;

temp = A;

B-A

A = b;

Temp-B

b = temp;

//

Use only A and B to achieve a two number worth of exchange

int a = ten, B = 20;

A = a + B;

b = a A;

A = a-B;

Expressions: There are constants, variables, and operators, and expressions generally have a result

3 + 5 5

int a = 10,b = 20;

A + = b;;;;;

A semicolon is the end flag for a statement, and the expression is a semicolon, which is the statement

Basic input and OUTPUT functions

printf ("hello\n world\n");

//

int a = ten, B = 20;

printf ("a =%d B =%d\n", b,a);

float f = 3.14;

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

Keep three digits after the decimal point

printf ("%.3f\n", f);

//

char c = ' W ';

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

int a = 10;

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

++a a first +1, then the result after using +1

a++ the value of a first, then a +1 operation on a

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

//

// %

printf ("percent");

printf ("\ \");

//

int a = 0;

Using Input functions

scanf ("%d", &a);

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

Enter two numbers, and then swap the values of the two numbers and print the exchanged values

int a = 0, b = 0;

scanf ("%d%d", &a,&b);

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

Define two variables

Enter the content you want to swap in

Exchange process

Results after the output exchange

int a = 10,b = 20;

scanf ("%d%d", &a,&b);

Do not add \ n after the input function%d, and will be offset by the manual carriage return

A = a + B;

A = a-B;

A = a-B;

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

return 10;

}

C1-Basic Concepts

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.