栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

闲杂篇(一)vs2017 c语言、c++从一个函数返回多个参数给主函数|c++函数之间结构体如何传递参数

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

闲杂篇(一)vs2017 c语言、c++从一个函数返回多个参数给主函数|c++函数之间结构体如何传递参数

函数返回多个参数给主函数| 函数之间结构体如何传递参数
笔者,最近因为学校项目需要,又捡起了vs2017来写算法
后面会更新矩阵使用方法,和自己写的一些矩阵功能,有兴趣的关注一波~
不多BB,直接上代码(共两种方法)

main.cpp

#include 
using namespace std;
#include "jiegouti.h"

int main() {
	cout << "*********************************************************************" << endl;
	cout << "vs2017 从一个函数返回多个参数给主函数|函数之间结构体如何传递参数" << endl;
	cout << endl << endl;
	
	listptr a = NULL;
	a = (listptr)malloc(sizeof(list));
	*a = (re)malloc(sizeof(Result));
	a= first(1, 2);
	printf("第一种方法:------------------------------n");
	cout << *((*a)->s_arr) << endl;
	printf("position:%d ns_arr:%d,%d,%d", (*a)->position,(*a)->s_arr[0], (*a)->s_arr[1], (*a)->s_arr[2]);


	cout << endl << endl;
	
	PARAMSAVE   set;
	set = second(1, 2);
	printf("n第二种方法:------------------------------n");
	printf("position:-------------------------n");
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 10; j++)

			printf("%f ", set.position[i][j]);
		cout << endl;
	}
		
	printf("s_arr:-------------------------n");
	for (int i = 0; i < 10; i++)
		printf("%f :", set.s_arr[i]);
	system("pause");

}

第二个文件

jiegouti.h

#pragma once
#ifndef JIEGOUTI_H
#define JIEGOUTI_H


typedef struct
{
	int position[2][3];;
	int s_arr[3];
}Result,*re;
typedef re list, *listptr;
extern listptr first(int x, int y);



typedef struct ParamSave {
	double position[3][10 + 1];
	double s_arr[10];
}PARAMSAVE;
extern PARAMSAVE second(int startPoint, int middlePoint);

#endif JIEGOUTI_H 

头文件

jiegouti.cpp

#include 
using namespace std;
#include "jiegouti.h"

listptr first(int x, int y) {
	listptr ret = NULL;
	ret = (listptr)malloc(sizeof(list));
	*ret = (re)malloc(sizeof(Result));

	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			(*ret)->position[i][j] = x + y;
		}
	}
	(*ret)->position[0][0] = x+y;
	(*ret)->s_arr[0] = 1;
	(*ret)->s_arr[1] = 1;
	(*ret)->s_arr[2] = 1;
	return ret;

}

PARAMSAVE   haha;
PARAMSAVE second(int x, int y) {

	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 10; j++)

			haha.position[i][j] = x + y;
	for (int i = 0; i < 10; i++)
		haha.s_arr[i] = 1;
	return haha;
}




资源领取:

1.在公众号后台领取,里面有我分享的学习资源,文件命名:vs2017结构体传参
2.或者去找我上传到压缩包《vs2017 c语言、c++从一个函数返回多个参数给主函数|c++函数之间结构体如何传递参数》

后续更新ST语言文件读取cvs

codesys工程ST语言学习笔记(二)写文件操作与添加库方法
codesys工程ST语言学习笔记(三)读文件操作txt,访问hello world 文件

【关注微信公众号一起来交流】
!
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1004768.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号