[C tips] the array name must be a pointer to the first element of the array?

Source: Internet
Author: User
Countless textbooks have hardly taken this seriously. Is the array name a pointer to the first element of the array? Guess the following Code What is the output: Char Ga [] =   " Abcdefghijklm " ;

Void My_array_func ( Char Ca [ 10 ]) {
Printf ( " Address of array Param = % # x \ n " , & CA );
Printf ( " Address of Ca [0] = % # x \ n " , & Ca [ 0 ]);
Printf ( " Address of Ca [1] = % # x \ n " , & Ca [ 1 ]);
Printf ( " ++ Ca =%# x \ n " , ++ CA );
}

Void My_pointer_func ( Char   * Pa) {
Printf ( " Address of PTR Param = % # x \ n " , & Pa );
Printf ( " Address of PA [0] = % # x \ n " , & Pa [ 0 ]);
Printf ( " Address of PA [1] = % # x \ n " , & Pa [ 1 ]);
Printf ( " ++ PA =%# x \ n " , ++ Pa );
}

Int Main ()
{
Printf ( " Address of Global Array = % # x \ n " , & Ga );
Printf ( " Address of Ga [0] = % # x \ n " , & Ga [ 0 ]);
Printf ( " Address of Ga [1] = % # x \ n " , & Ga [ 1 ]);
My_array_func (GA );
My_pointer_func (GA );

System ( " Pause " );
Return   0 ;
}

If you find that the address of the first element of the result array parameter is different from that of the array parameter, please print it in two my_func.* (& Ca)And* (& PA). If you use sizeof to check the size of the parameter array at this time, you will be more surprised. Try it yourself ;-)

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.