C Language Review 5

Source: Internet
Author: User

1. Two-dimensional array: is a special one-dimensional array

Full initialization:

1) int a[2][3]={{1,2,3},{2,3,4}};

2) Continuous assignment int a[2][3]={1,2,3,2,3,4};

3) The length of the first dimension can be omitted and the second dimension cannot be saved

int a[][3]={1,2,3,2,3,4};

Partial initialization

int a[2][3]={1,2,3};

Define a post-initialization first

2. Traversal of two-dimensional arrays

Dual cycle

3. Storage of two-d arrays, pre-column, continuous storage

The first address of a two-dimensional array = array name =&a[0]=&a[0][0]

Computes the total number of bytes consumed by the array name sizeof (a);

Number of bytes per line sizeof (a[0]);

How many columns are in each row: The number above/the number of bytes occupied by each element

Number of lines: sizeof (a)/sizeof (A[0])

4. String (double quotation marks, ending with a)

To save a string with a character array

1) Char str[4]={"Hello"};

2) Char str[4]= "Hello";

3) Char str[]= "Hello";

String output

Print ("%s", str);//str is the first address of a string

Print ("%s", &str[0]);//%s starts printing from the given address until the end of the

%s input, if the string has a space, then the character after the space cannot be received save

To calculate the length of a string:

1) Use strlen (str); function

2) Iterate through the array, encounter the end of the cycle, return the number

String handling functions

1) input/output function, including stdio.h

Puts output a string, puts (the first address of the character array);

Gets input a string, gets (character array name) using the get will give a warning that there is an out-of-bounds problem. You can receive spaces, but you cannot format the session output.

2) string connection function, including string.h

strcat (OLDSTR,NEWSTR);//Connect newstr to oldstr behind, oldstr to be large enough

strcpy (OLDSTR,NEWSTR);//cover oldstr,oldstr with NEWSTR to be large enough

strcmp (str1, str2);//compare str1 and str size, STR1>STR2 return greater than 0

Strlen (STR1);//Calculate the length of a string

5. Pointers: Address

Pointer variable: The variable that holds the pointer

Pointer variable definition: data type * pointer variable name or data type * pointer variable name

Initialization of pointer variables: int *p=&a;int *p=null;

Get the memory space pointed to by the pointer variable with *P

If the pointer variable definition is not initialized later, this pointer variable holds a garbage number, which is called a wild pointer

C Language Review 5

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.