Introduction to basic knowledge of C language learning (I): Basic knowledge of language learning

Source: Internet
Author: User
Tags constant definition

Introduction to basic knowledge of C language learning (I): Basic knowledge of language learning

This series is prepared for learning ios, and can also be used as a tutorial for getting started with C language.

Printf function:

The printf function is used as an output statement to output the statements that the user wants to output.

For example: printf ("I'm a handsome guy ~~ ");

Printf ("Number 1 = % d, number 2 = % d", 10, 20); // % d is explained together.

/*

% D: enter int and short data, for example, printf ("Number 1 = % d, number 2 = % d );

% Ld: Fill in long data, such as printf ("Number 1 = % ld, number 2 = % ld );

% F: Fill in float data, such as printf ("Number 1 = % f, number 2 = % f", 10f, 20f );

% Lf: enter data of the double type, for example, printf ("Number 1 = % lf, number 2 = % lf );

% C: enter data of the char type, such as printf ("Number 1 = % c, number 2 = % c", '1', '2 ');

Format the output content:

Printf ("string to be output", Value List). Note that the values must be separated by commas.

*/

Data Type in C language:

The six keywords short, int, long, char, float, and double represent the six basic data types in C.

1. Introduction to various data types

Integer 1.1

Integer types include short integer, integer, and long integer.

1.1.1 short integer

Short a = 1;

1.1.2 integer

It generally occupies 4 bytes (32 bits). The highest bit represents the symbol. 0 represents a positive number. 1 represents a negative number. The value range is-2147483648 ~ 2147483647. The storage order in the memory is after the top and high positions. For example, the storage of 0x12345678 in the memory is as follows:

Address: 0x0012ff78 0x0012ff79 0x0012ff7a 0x0012ff7b

Data: 78 56 34 12

Definition: Use the int keyword, for example:

Int a = 6;

1.1.3 long integer

Long a = 10;

1.2 floating point type

Floating Point models include single-precision and double-precision models.

1.2.1 single precision type

Float Type, also known as solid type, also known as single precision. It generally occupies 4 bytes (32 bits ),

Float a = 4.5;

Address: 0x0012ff78 0x0012ff79 0x0012ff7a 0x0012ff7b

Data: 00 00 90 40

1.2.2 Double Precision type

Generally 8 bytes (64-bit)

Double a = 4.5;

Address: 0x0012ff78 0x0012ff79 0x0012ff7a 0x0012ff7b 0x0012ff7c 0x0012ff7d 0x0012ff7e 0x0012ff7f

Data: 00 00 00 00 00 12 40

1.3 character type

In various systems, the character type occupies one byte (8 bits ). Definition:

Char c = 'a ';

You can also assign values using the ASCII code corresponding to the characters, as shown below:

Char c = 97;

Constants in C language:

The key word const for defining a constant. A constant is defined and cannot be changed.

Constant definition:

Literal representation: Write a value directly. For example, 1; 10.3; 'a ';

General Definition: const type variable name = value;

 

C language variables:

Variable definition:

General Definition: type variable name = variable value;

Variable with or without symbols:

Generally, all numeric variables are signed variables. to define an unsigned variable, use the unsigned keyword,

Variables With a keyword can only define numbers greater than or equal to 0.

Output Variables of this type: short and int are both directly % u, for example: printf ("% u \ n", 12); long is printf ("% lu \ n ", 12 );

      

Naming rules for variables in C language:

 

1. The name should be meaningful;

2. It can only start with an underscore, letter, or dollar sign ($;

3. Chinese characters can be used in mac, but not recommended (not in Standard c ).

4. Keywords cannot be used as variable names.

5. Use the camper name method (the first letter of the first word is lowercase, and the first letter of the second word is capitalized ).

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.