⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 参数传递.cpp

📁 此代码是在多线程下
💻 CPP
字号:
// 参数传递.cpp : Defines the entry point for the console application.
//全局变量传递

#include "stdafx.h"
#include<iostream.h>
#include<process.h>
#include<windows.h>//不用此文件头则出错
//用全局变量传递数据
struct node{
	int data;
}*q;

DWORD WINAPI mythread(void *p)
{
	cout<<"the number is:"<<q->data<<endl;

    DWORD exitCode;
	ExitThread(exitCode);

	return 0;
}


int main(int argc, char* argv[])
{
	DWORD dw;
	HANDLE handle;
	q=(struct node *)malloc(sizeof(struct node));
	cout<<"Input number:";
	cin>>q->data;
	cout<<endl;
	Sleep(1000);

	handle=CreateThread(NULL,0,mythread,NULL,0,&dw);
	Sleep(1000);

	CloseHandle(handle);

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -