Find array length sizeof

Source: Internet
Author: User

When an array is passed as a parameter, it degrades into a pointer and requires the length of the array to be evaluated inside the main function.

 #define  _CRT_SECURE_NO_WARNINGS 1#include <stdio.h> Void fun (Int arr[], int len) {    printf ("---%d\n",  sizeof (arr)); &NBSP;&NBSP;&NBSP;&NBSP;PRINTF ("---%d\n",  sizeof (Arr[0])); &NBSP;&NBSP;&NBSP;&NBSP;PRINTF ("---len =  %d\n ",  sizeof (arr)  / sizeof (arr[0]);      printf (" ____len=%d\n ",  len);} Int main () {    int arr[10];    printf ("%d\n",  sizeof ( ARR));     printf ("%d\n",  sizeof (Arr[0]));     printf ("len =  %d\n ",  sizeof (arr)  / sizeof (arr[0]);     fun (arr, sizeof (arr)  / sizeof (arr[0]));     system ("pause");     return 0;} 

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s2.51cto.com/wyfs02/m02/75/e8/wkiom1zeycrsi4smaabawfve_ok248.png "title=" 360 feedback 16400228526034.png "alt=" Wkiom1zeycrsi4smaabawfve_ok248.png "/>


sizeof (ARR)//Calculate the memory size of the array
sizeof (arr[])//Find the byte of array element
sizeof (ARR)/sizeof (Arr[0]//Find array length or number of elements

From the above example, it can be seen that the length of the array is not within the function


Find array length sizeof

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.