ubuntu C++ VScode 指针练习 字符串数组 改变字符串数组中的元素

  • 时间:
  • 浏览:
  • 来源:互联网

定义一个字符串数组,通过指针把数组里的第三个元素更改掉

#include <iostream>
#define n 4

using namespace std;

//n = 5;
string Array_str[n] = {"a","b","c","d"};
string *pointer_str = NULL;

int main()
{
	for (int i = 0; i < n; i++)
	{
		pointer_str = &Array_str[i];
		//cout << "Array_str["<< i <<"]=" << Array_str[i] << endl;
		cout << "i=" << i << "," << "*pointer_str=" << *pointer_str << endl;
		if (pointer_str == &Array_str[2])
		{
			*pointer_str = "e";
			Array_str[2] = *pointer_str;
		}
		
	}
	for (int i = 0; i < n; i++)
	{
		cout << "Array_str["<< i <<"]=" << Array_str[i] << endl;
	}
}

 

本文链接http://xiahunao.cn/article/show-994402.html