c ++查找字符串
Program 1:
程序1:
#include <iostream>
using namespace std;
int main()
{
char* STR[] = { "HELLO", "HIII", "RAM", "SHYAM", "MOHAN" };
cout << (*STR + 2)[2];
return 0;
}
Output:
输出:
O
Explanation:
说明:
Here we create an array of pointers to store strings. Now, look at the cout statement,
在这里,我们创建一个指针数组来存储字符串。 现在,看看cout语句,
cout<<(*STR+2)[2];
The above statement will print the element of the 4th index of 1st string because pointer STR pointing the 1st string that is "HELLO" so the above statement will print 'O'.
上面的语句将打印第一个字符串的第4 个索引的元素,因为指针STR指向“ HELLO”的 第一个字符串,因此,上面的语句将打印“ O” 。
Program 2:
程式2:
#include <iostream>
using namespace std;
int main()
{
char STR[5][8] = { "HELLO", "HIII", "RAM", "SHYAM", "MOHAN" };
cout << STR[2] + 1;
return 0;
}
Output:
输出:
AM
Explanation:
说明:
Here, we created a program two-dimensional array for strings. Now look the cout statement,
在这里,我们为字符串创建了一个程序二维数组。 现在看一下cout语句,
cout<<STR[2]+1;
In the above statement, STR[2] is pointing to the 'R' in the string "RAM" and we move pointer one position ahead then it will print "AM" on the console screen.
在上面的语句中, STR [2]指向字符串“ RAM”中的“ R ” ,我们将指针向前移动一个位置,然后它将在控制台屏幕上打印“ AM” 。
Recommended posts
推荐的帖子
C++ Arrays | Find output programs | Set 1
C ++数组| 查找输出程序| 套装1
C++ Arrays | Find output programs | Set 2
C ++数组| 查找输出程序| 套装2
C++ Arrays | Find output programs | Set 3
C ++数组| 查找输出程序| 套装3
C++ Arrays | Find output programs | Set 4
C ++数组| 查找输出程序| 套装4
C++ Looping | Find output programs | Set 1
C ++循环| 查找输出程序| 套装1
C++ Looping | Find output programs | Set 2
C ++循环| 查找输出程序| 套装2
C++ Looping | Find output programs | Set 3
C ++循环| 查找输出程序| 套装3
C++ Looping | Find output programs | Set 4
C ++循环| 查找输出程序| 套装4
C++ Looping | Find output programs | Set 5
C ++循环| 查找输出程序| 套装5
C++ Default Argument | Find output programs | Set 1
C ++默认参数| 查找输出程序| 套装1
C++ Default Argument | Find output programs | Set 2
C ++默认参数| 查找输出程序| 套装2
C++ Class and Objects | Find output programs | Set 1
C ++类和对象| 查找输出程序| 套装1
C++ Class and Objects | Find output programs | Set 2
C ++类和对象| 查找输出程序| 套装2
C++ Class and Objects | Find output programs | Set 3
C ++类和对象| 查找输出程序| 套装3
C++ Class and Objects | Find output programs | Set 4
C ++类和对象| 查找输出程序| 套装4
C++ Class and Objects | Find output programs | Set 5
C ++类和对象| 查找输出程序| 套装5
翻译自: https://www.includehelp.com/cpp-tutorial/arrays-find-output-programs-set-5.aspx
c ++查找字符串