C-language pointer function and function pointer

Source: Internet
Author: User

Example one: function pointers

Note that the pointer function is different from the function pointer representation method, so don't confuse it. The simplest way to discern is to see if the pointer in front of the function name is enclosed in parentheses (), and if it is included as a function pointer, the pointer function if no parentheses include *.

Pointer function: When a function declares its return value as a pointer, it actually returns an address to the calling function for use in an expression that requires a pointer or address.

#include"stdio.h"int* GetDate (intWkintdy); intMain () {intWk,dy;  Do{puts ("Enter Week (1-5) Day (1-7)"); scanf ("%d%d",&wk,&dy); }             while(wk<1|| Wk>5|| dy<1|| Dy>7); printf ("%d\n",*GetDate (Wk,dy)); }int* GetDate (intWkintdy) {    Static intcalendar[5][7]=          {               {1,2,3,4,5,6,7},               {8,9,Ten, One, A, -, -},               { the, -, -, -, +, -, +},               { A, at, -, -, -, -, -},               { in, -, to,-1}            }; return&calendar[wk-1][dy-1]; }        

#include"stdio.h"intMain () {Chara[]="abcdef";p rintf ("This is an address of an array element%x\n", a);p rintf ("This is an entire first address of an array object%x\n",&a);p rintf ("%d\n",sizeof(* (A +1)) );p rintf ("%d\n",sizeof((&a+1))); return 0; }

C-language pointer function and function pointer

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.