The path of C pointer programming and the path of pointer Programming

Source: Internet
Author: User

The path of C pointer programming and the path of pointer Programming

This time we sorted out the function pointers and pointer functions.

This is a pointer call:

Code:

# Include <iostream>
# Include <cstdio>
Using namespace std;
Typedef unsigned char unit8_t;
Extern void swapdata (unit8_t dat_x, unit8_t dat_y );
Int main ()
{
Unit8_t x, y;
Scanf ("% d", & x, & y );
Printf ("Before change: x = % d, y = % d \ n", x, y );
Swapdata (x, y );
Printf ("after exchange: x = % d, y = % d \ n", x, y );
Return 0;
}





Void swapdata (unit8_t dat_x, unit8_t dat_y)
{
Unit8_t temp;
Temp = dat_y;
Dat_y = dat_x;
Dat_x = temp;
}

Next:

// Common parameters and pointer Parameters
// Define a pointer to a function
// Int (* P_output) is a function pointer.
// The return value is int type (* p_output) and is a pointer function.
# Include <iostream>
# Include <cstdio>
Using namespace std;
Void output ();
Void output ()
{
Cout <"LongMai is OK \ n" <endl;
}
Int main ()
{
Void (* p_output )();
P_output = output;
(* P_output )();
Return 0;
}





// Pointer Function
// The return value indicates that the pointer function is a pointer function.
// Int * p_fun (). This is a pointer function.
// Int (* p_fun (). This is the function pointer.
# Include <iostream>
# Include <cstdio>
Int * p_func ()
{
/*
*
**/
}
Int main ()
{
Int * p_funx ();
/****
*
*
****/


Return 0;
}




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.