*str[] 和 str[][] 之间的区别
Difference between *str[] and str[][]
我不明白这段代码中 *str[] 的使用,它与这段代码中使用的 str[][] 有什么不同吗?
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
int main()
{
char a[10], b[10], c, buffer[50], str[1][9], s[10];
//decalaring char a, b, buffer, str[][], s//
int y;
ofstream out;
out.open("output.cpp");
out<<("nOPCODEtMACHINE_CODEn");
do
{
y = 0;
cout<<"ENTER THE OPCODE&MACHINE CODE";
cin>>a>>b;
out<<"n"<<a<<"t"<<b<<"t"<<"n";
cout<<"PRESS 1 TO CONTINUE";
cin>>y;
}while(y == 1);
out.close();
ifstream in;
in.open("output.cpp");
while(in)
{
c = in.get();
cout<<c;
}
in.close();
cout<<"ENTER THE OPCODE TO SEARCH";
cin>>s;
in.open("output.cpp");
in.getline(buffer,50);
while(in)
{
*str[0] = ' '; // i dont understand the use of *str[] here, is it diff from str[][]?
*str[1] = ' ';
in>>str[0];
in>>str[1];
if(strcmpi(str[0], s) == 0)
{
cout<<"n"<<str[0]<<"t"<<str[1];
}
}
return 0;
}
*x
的意思是"取消引用指针x
"。现在,每当一个数组处于语言需要指针的位置时,它就会隐式衰减到指向第一个元素的指针。
所以
*str[0]=' ';
意思是"将' '
分配给 1 元素字符数组str[0]
的第一个元素,它本身就是 9 元素数组的第一个元素str
"。
它的意思与
str[0][0] = ' ';
可以说应该是这样写的。或者str
应该首先被宣布为char str[9]
。
相关文章:
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- int(c) 和 c-'0' 之间的区别。C++
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- C++ - "!pointer"和"pointer == nullptr"的区别?
- C++ 使用 assign 函数的字符串与直接使用 '=' 更改值的字符串之间的区别
- std::atomic和std::condition_variable wait,notify_*方法之间的区别
- 在 .h 文件中的类中声明静态变量和在.cpp文件中声明"global"变量有什么区别
- 我是C++编程的新手,这些代码之间有什么区别,我应该使用哪一个
- 在 const 函数中通过引用和指针返回之间的区别
- 我想知道长双倍和双倍之间的区别
- 返回常量对象引用 (getter) 和仅返回字符串有什么区别?
- 返回递归调用和仅递归调用的区别
- Python str to C++ to Python str
- Qt:remove() 和 rmdir() 有什么区别
- 这 4 个 lambda 表达式之间有什么区别?
- str.clear() 和 str 之间的区别 = " "
- 初始化 stringstream.str( a_value ) 和 stringstream << a_value 之间的区别
- << s.str() 和 << s.rdbuf() 之间的区别
- *str[] 和 str[][] 之间的区别
- b/w char* str[]、char* str和char str[]的区别