Usage of C++ function pointer

Publisher:吾道明亮Latest update time:2015-05-08 Source: 51heiKeywords:C++ Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
A function pointer is a pointer variable that points to a function. Therefore, a "function pointer" itself should first be a pointer variable, but the pointer variable points to a function. The following program shows us how to use it.


 // 0302.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int fun(int *pa,int *pb)
{
int out=(*pa)*(*pb);
return out;
}

int _tmain(int argc, _TCHAR* argv[])
{
int a=10,b=20;
int(*funn)(int*pa,int*pb);//The first step is to define the function pointer
funn=fun;//The second step, pointer = function name
int sum=funn(&a,&b);//The third step, the function pointer operation is pointed to the function
printf("%d ",sum);
return 0;
}

Keywords:C++ Reference address:Usage of C++ function pointer

Previous article:About C++ pointer types and forced type conversion
Next article:Comprehensive use of C language for, while, if-else, return statements

Recommended ReadingLatest update time:2024-11-16 14:41

Porting of LWIP-1.3.0 and DM9000 based on S3C2440 on UCOS-II-2.8.6
I usually run on Linux, and I feel a little uncomfortable jumping to UCOS for a while. First of all, the compiler, GCC is a good choice, but GDB debugging is too troublesome. ADS combined with the simulator is a very good debugging environment, so I moved the code to ADS, which is completely independent of Linux, an
[Microcontroller]
Porting of LWIP-1.3.0 and DM9000 based on S3C2440 on UCOS-II-2.8.6
After the EU pushed for the USB-C unified interface, the USB official accidentally reversed
Some time ago, the European Union proposed a resolution requiring mobile phone manufacturers to unify the interface to USBC. Those who have used this interface know its advantages. Android manufacturers have now basically upgraded to the USBC interface, but Apple sticks to the lightning interface and is unwilling to u
[Mobile phone portable]
Porting OpenCV2.0.0 to ARM9 (II) (JZ2440----S3c2440)
1. Cross-compile libjpeg In order to enable OpenCV to process jpeg images, we must cross-compile libjpeg in advance. The version used here is jpegsrc.v6b. Download address: https://sourceforge.net/projects/libjpeg/files/libjpeg/6b/ The installation package used here: jpegsrc.v6b.tar.gz. (1) Unzip and configure jpegs
[Microcontroller]
Porting OpenCV2.0.0 to ARM9 (II) (JZ2440----S3c2440)
The Structure and Software Design of S3C825A Microcontroller
  1 Internal structure of S3C825A microcontroller   The internal structure block diagram of S3C825A is shown in Figure 1. From Figure 1, we can see that the microcontroller has the following features:   ●Use SAM88RC as the central processing unit;   ●With 48KB on-chip ROM and 2096byte register space;   ●With
[Microcontroller]
The Structure and Software Design of S3C825A Microcontroller
Development of ADμC7O26 hardware system and its application in medical instruments
0 Introduction As people's living standards continue to improve, people's attention to their own health has also risen to an unprecedented level. Today, more and more high-tech means are beginning to be used in the design of medical instruments. Physiological parameter detection equipment such as electr
[Medical Electronics]
Development of ADμC7O26 hardware system and its application in medical instruments
Environmental noise measuring instrument based on 89C51 microcontroller
   1 Introduction      Environmental noise monitoring is an important link for humans to improve their quality of life and strengthen environmental protection. Large-scale environmental noise monitors have been erected on the streets in prosperous neighborhoods and residential areas of major cities. However, most of t
[Microcontroller]
STM32 simulates I2C program
/*******************************************************************************   Test platform: STM32F103ZET6 minimum system *******************************************************************************/ static void i2cDelay() {     volatile int i = 7;     while (i)     i--; } // During the SCL high level period
[Microcontroller]
Knob-type keyboard and its interface technology with AT89C52
Introduction Nowadays, single-chip microcomputer technology is developing rapidly, and single-chip microcomputer systems have been widely used in various fields of the national economy. Many single-chip microcomputer application systems require input devices, and the typical input device is the key
[Microcontroller]
Knob-type keyboard and its interface technology with AT89C52
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号