C++ 带有c++; intmain() { int x=5,y=5; 整数和=相加(&x,&y); 库特
字面上我可以使用C++ 带有c++; intmain() { int x=5,y=5; 整数和=相加(&x,&y); 库特,c++,C++,字面上我可以使用a[i]或p1[i] 是的,对于原始数组符号或指针,解引用的工作方式相同 示例中的a符号在使用时将衰减为int*指针(p1=a;) 使用代码< >代码> P1[i] 只是针对 *(P1+i)的语法糖。< /P>请在发布问题之前检查它是否已经存在,否则,时间会被阻止发布。“……我相信,我必须用指针指向C++中的代码,并制作高效程序。”不,这是完全错误的接近C++的态度。你不应该处理第一的原始指针或原始数组。有C++标准库支持,支持代码< > STD::数组< /COD>和 STD:
a[i]
或p1[i]
是的,对于原始数组符号或指针,解引用的工作方式相同
示例中的a
符号在使用时将衰减为int*
指针(p1=a;
)
使用代码< >代码> P1[i] <代码>只是针对<代码> *(P1+i)的语法糖。< /P>请在发布问题之前检查它是否已经存在,否则,时间会被阻止发布。“……我相信,我必须用指针指向C++中的代码,并制作高效程序。”不,这是完全错误的接近C++的态度。你不应该处理第一的原始指针或原始数组。有C++标准库支持,支持代码< > STD::数组< /COD>和<代码> STD::向量< /代码>。至少在这个千年里,这比初学者想象的要重要得多。@Baum这是他们愚蠢的老师/教授想要看到的。我真的很生气用我的税款资助这些人。虽然还不清楚,但可能是一个很好的欺骗目标。谢谢,现在清楚了。我还有一个问题要问you@AmithRc如果你有另一个问题问另一个问题。
int main()
{
int x=5,y=5;
int sum = add(&x,&y);
cout<<"Address of x is"<<&x<<endl;
cout<<"Address of y is"<<&y<<endl;
cout<<"The addition of a and b is"<<sum<<endl;
int a[5]={1,2,3,4,5};
int *p1;
p1=a;
for(int i=0;i<5;i++)
{
cout<<"The Address of the Array elements is"<<p1+i<<endl;
cout<<"The value of the array element is"<<*(p1+i)<<endl;
}
cout<<endl;
cout<<endl;
for(int i=0;i<5;i++)
{
cout<<"The Address of the Array elements is"<<&p1[i]<<endl;
cout<<"The value of the array element is"<<p1[i]<<endl;
}
cout<<"address of a is "<<p1<<endl;
int arrayTotal= SumofArray(a,5);
cout<<"The sum of array is"<<arrayTotal <<endl;
}