将一组字符传递给函数

编程入门 行业动态 更新时间:2024-10-28 06:27:19
本文介绍了将一组字符传递给函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

很抱歉这个非常愚蠢的问题,但我显然还有很长的路要走! 有人可以帮我把数组传递给一个函数。这是一个开始 点。 void TheMainFunc() { //代码体... TCHAR myArray [512]; DoStuff(myArray); } 无效DoStuff(TCHAR theArray) { ... } 我无法理解变量myArray的变化。是 - 它是一个 指向内存地址的指针,该内存地址可以容纳一个TCHAR(如果是 UNICODE则是一个宽字符)? 谢谢 John - --- 如果你需要亲自回复,附加文字我的 电子邮件地址中的域名。 谢谢

Sorry for this very dumb question, but I''ve clearly got a long way to go! Can someone please help me pass an array into a function. Here''s a starting point. void TheMainFunc() { // Body of code... TCHAR myArray[512]; DoStuff(myArray); } void DoStuff(TCHAR theArray) { ... } I can''t quite get my head around what the variable "myArray" is - is it a pointer to a memory address that would hold a TCHAR (a wide char if UNICODE)? Thanks John -- --- If you need to reply personally, append "text" to the domain name in my email adr. Thanks

推荐答案

jr写道: jr wrote: 对于这个非常愚蠢的问题感到抱歉,但我显然已经走了很长的路要走!有人可以帮我把一个数组传递给一个函数。 您无法将数组传递给函数。通常,会传递一个指向数组' 第一个元素的指针。 这是一个起点。 void TheMainFunc( ) {//代码体...... TCHAR myArray [512]; DoStuff(myArray); } void DoStuff(TCHAR theArray) { ... } 我不能完全理解变量 myArray的"是 - 它是一个指向内存地址的指针,它将容纳一个TCHAR(如果是UNICODE则是一个宽字符)? myArray是一个TCHAR数组。你的DoStuff函数接受一个参数 类型为TCHAR,即_one_字符。 尝试: void DoStuff(TCHAR * theArray ) Sorry for this very dumb question, but I''ve clearly got a long way to go! Can someone please help me pass an array into a function. You cannot pass arrays into functions. Usually, a pointer to the array''s first element is passed instead. Here''s a starting point. void TheMainFunc() { // Body of code... TCHAR myArray[512]; DoStuff(myArray); } void DoStuff(TCHAR theArray) { ... } I can''t quite get my head around what the variable "myArray" is - is it a pointer to a memory address that would hold a TCHAR (a wide char if UNICODE)? myArray is an array of TCHAR. Your DoStuff function takes a parameter of type TCHAR, i.e. _one_ character. Try: void DoStuff(TCHAR* theArray)

当你将数组传递给DoStuff时,它会自动转换为指向第一个元素的指针。

When you pass the array to DoStuff, it will be automatically converted into a pointer to its first element.

2004年1月19日星期一23:54:58 -0000 comp.lang.c ++," jr" < jo ***@tele.co.uk>据称写了: On Mon, 19 Jan 2004 23:54:58 -0000 in comp.lang.c++, "jr" <jo***@tele.co.uk> was alleged to have written: TCHAR myArray [512]; DoStuff(myArray); } void DoStuff(TCHAR theArray) { 无效DoStuff(TCHAR * theArray) { 我无法理解我的想法变量myArray是 - 它是一个指向内存地址的指针,它可以容纳一个TCHAR(如果是UNICODE则是一个宽字符)? TCHAR myArray[512]; DoStuff(myArray);}void DoStuff(TCHAR theArray){ void DoStuff(TCHAR * theArray) { I can''t quite get my head around what the variable "myArray" is - is it apointer to a memory address that would hold a TCHAR (a wide char ifUNICODE)?

不,它'不是指针,它是256个实例存储的实际存储空间 TCHAR。但是你经常可能会把它称为指针,并且C是非常矛盾的,将数组变量名称转换为 指针,其中只有很少的挑衅非数组类型需要 运算符&得到指针。 C ++可能更愿意一直 需要运算符&,但与C一起兼容。

No, it''s not a pointer, it''s the actual storage for 256 instances of TCHAR. But you often may refer to it as if it was a pointer, and C is very ambivalent about that, converting the array variable name to a pointer with little provocation where non-array types would require operator& to get the pointer. C++ would probably prefer to consistently require the operator&, but goes along with C for compatibility.

David Harmon写道: David Harmon wrote: TCHAR myArray [512]; 我不能完全理解变量myArray的含义。是 - 它是一个指向内存地址的指针,它可以容纳一个TCHAR(如果是UNICODE则是一个宽字符?) TCHAR myArray[512]; I can''t quite get my head around what the variable "myArray" is - isit a pointer to a memory address that would hold a TCHAR (a wide charif UNICODE)?

不,它不是一个指针,它是256个 TCHAR实例的实际存储空间。

No, it''s not a pointer, it''s the actual storage for 256 instances of TCHAR.

当然可以吗? ;-)

Sure about that? ;-)

更多推荐

将一组字符传递给函数

本文发布于:2023-11-10 03:22:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574220.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   字符

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!