C language-pointer-type function (returning pointer-worthy function)

Source: Internet
Author: User
1 Function Type*Function Name (form parameter table)//A pointer function is a function that returns a pointer address.
2 {Function body}

After the function is executed, you can bring back a value to the main function. This value can be of the standard type or different types of pointer data. Then, you can use these pointers to indirectly access the relevant data.

For example, the strchr () function is used to search for a character in a string. If a character is found, the address of the character is returned. Otherwise, a null pointer is returned.

 1   # Include  <  Stdio. h  >  
2
3 Char * Strchr ( Char * STR, Char Ch)
4 {
5 While ( * Str ! = Ch && * Str ! = ' \ 0 ' )
6 {
7 Str ++ ;
8 }
9
10 Return STR;
11 }
12
13 Int Main ()
14 {
15 Char STR [] = " Liang Yan " ;
16 Char * P, ch;
17
18 Printf ( " Please input CH: " );
19 Scanf ( " % C " , & Ch );
20
21 P = Strchr (STR, CH );
22
23 If (* P)
24 {
25 Printf ( " Output The first STR address in octal format: % O \ n " , STR );
26 Printf ( " Character: % C \ t character % C address in string STR: % O \ n " , Ch, ch, P );
27 Printf ( " Position of the character in the string: % d \ n " , P - Str );
28 }
29 Else
30 Printf ( " Not found! \ N " );
31
32 Return 0 ;
33 }

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.