Introduction to the basic knowledge of C language learning (I.)

Source: Internet
Author: User

This series is designed to learn iOS and can also be used as a tutorial for getting started with the C language.

printf functions:

The printf function acts as an output statement, and the main function is to output the statements that the user wants to output.

For example: printf ("I am a handsome brother ~ ~");

printf ("Digital 1=%d, Digital 2=%d", 10,20);//%d will be explained together next.

/*

%d: Fill in Int,short type data, such as printf ("Digital 1=%d, Digital 2=%d", 10,20);

%LD: Fill in long type data such as printf ("Digital 1=%ld, Digital 2=%ld", 10,20);

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

%LF: Fill in a double type of data, such as printf ("Digital 1=%lf, Digital 2=%LF", 10,20);

%c: Fill in data of type char, such as printf ("Digital 1=%c, Digital 2=%c", ' 1 ', ' 2 ');

Formatted output:

printf ("String to Output", value list); Note the value is separated from the value by a comma (,) in English.

*/

Data types in the C language:

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

1. Introduction to various data types

1.1 Integral type

Shaping includes short integer, Shaping, and long-shaping.

1.1.1 Short Shaping

Short a=1;

1.1.2 Plastic Surgery

Typically 4 bytes (32 bits), the highest bit represents the symbol, 0 is a positive number, 1 is negative, the value range is -2147483648~2147483647, in memory the order of storage is status before, high, for example, 0x12345678 in memory storage as follows:

Address: 0x0012ff78 0x0012ff79 0x0012ff7a 0x0012ff7b

Data: 78 56 34 12

Definition: Using the INT keyword, for example:

int a=6;

1.1.3 Long Plastic

Long a=10;

1.2 Floating-point type

Floating-point types include single-and double-precision types.

1.2.1 Single-precision type

Floating-point type, also known as the real type, is called the single precision. Typically takes 4 bytes (32 bits),

float a=4.5;

Address: 0x0012ff78 0x0012ff79 0x0012ff7a 0x0012ff7b

Data: 00 00 90 40

1.2.2 Double-precision type

Typically 8 bytes (64 bits)

Double a=4.5;

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

Data: 00 00 00 00 00 00 12 40

1.3 Character types

In a variety of different systems, the character type takes up one byte (8 bits). Defined as follows:

Char c= ' a ';

You can also assign a value to the ASCII code that corresponds to the character, as follows:

Char c=97;

Constants in the C language:

A const keyword that defines a constant that is not and cannot be changed after it is defined.

Definitions of constants:

Literal notation: Direct write value. For example 1; 10.3; ' A ';

General definition: Const type variable name = value;

Variables in the C language:

The definition of a variable:

General definition: Type variable name = variable value;

There are no symbolic variables:

A variable of a generally defined numeric type is a signed variable, and if you want to define an unsigned variable, you need to use the unsigned keyword.

A variable with a keyword can only define numbers greater than or equal to 0.

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

      

Naming conventions for variables in the C language:

1, the name should have meaning;

2, can only use the underscore, the letter, the dollar sign ($) begins;

3, the MAC environment can be used in Chinese, but not recommended (standard C is not possible).

4, cannot use the keyword as the variable name.

5. Use the Hump naming method (the first letter is lowercase, the second word starts with the first letter capitalized).

Introduction to the basic knowledge of C language learning (I.)

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.