In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
What this article shares with you is about how functions in C++ return multiple values. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article. Let's take a look at it with the editor.
1. There is a thorny problem: (how to return multiple values by the CAccord Cure + function? )
I encapsulate the algorithms into different functions, and it's easy to call this function in matlab, as follows:
% matlab function example function [outputArg1,outputArg2] = test_func (inputArg1,inputArg2)% test_func A summary of this function is shown here. The detailed description outputArg1 = inputArg1;outputArg2 = inputArg2;end is shown here.
In matlab, it's easy to output multiple values.
However, it is not so easy for you to return (output) multiple values in a C function.
two。 What shall I do? (code example)
There are three methods, and I will only say the most commonly used and effective one.
When the function is called, pass the parameter with the address and use the pointer to change its value
In this way, the modified value becomes the original parameter.
Go directly to the code:
1) main function / / main.cpp
/ / main.cpp#include # include "mycal.h" int main () {int a = 2ntint b = 1poliint citint c1ittmyaddyogfunc (a maestro bmemorie cepagenet C 1); printf ("c =% d\ n", c); printf ("C1 =% d\ n", C1); return 0;}
2) Sub-function / / mycal.cpp
/ / mycal.cpp#includeint myadd_func (int a _ line int bline int * c, int * c _ 1) {* c = a + b _ politic _ c _ 1 = a + b _ blank 100 percent return 0;}
3) header file corresponding to subfunction
/ / mycal.hint myadd_func (int a, int b, int * c, int * C1)
Running result:
The above is how the function in C++ returns multiple values. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.