C-two-dimensional arrays as function arguments, character arrays

Source: Internet
Author: User
1. If the function parameter is a one-dimensional array, then we can pass a two-dimensional array of 1 rows-a one-dimensional array 2. A two-dimensional array can be used as a parameter to a function: if the parameter of the function is a two-dimensional array, the passed argument must also be a two-dimensional array of the same type 3. As with the same-dimensional array, when a two-dimensional array is an argument to a function, the function is also a pointer to the passed-in two-dimensional array, which is manipulated by a pointer to an incoming two-dimensional array 4. When a two-dimensional array is an argument to a function, the number of rows may not be written, but the number of columns must be 5. So, as with a one-dimensional array, when a two-dimensional array is a function parameter, the parameters of the function are the rows of the array, the two parameters of the column, the standard notation: void Test (int rows, int cols, int arr[][cols]) {} character array: 1. Default value problem for character array: Declares a character array, does not assign a value to the element of this character array, then the element of this character array is a value, the memory garbage value is 2. When you declare a character array, the other characters are initialized to ' 3 ' if some elements are initialized. Character array cannot be stored in Chinese; 4. If the length of the string array is less than or equal to the length of the string, there will be no storage condition 5.  Therefore, when using character arrays to store string data, it is best not to specify a length of 6 when declaring.  scanf ("%s", array); There is no need to bring & at this time, because the name of the array in this time itself can represent its first address 7. When inputting strings with scanf, it is unsafe if the input length is greater than the length of the array; If a space is entered, the input is considered to end 8. You cannot use sizeof to calculate the length of a string (it is possible that the actual string is only part of the array), using strlen (), and another method: The while loop, counting from the first, and encountering the end of a.

C-two-dimensional arrays as function arguments, character arrays

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.