c ++查找字符串_C ++数组| 查找输出程序| 套装5

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

推荐的帖子

翻译自: https://www.includehelp.com/cpp-tutorial/arrays-find-output-programs-set-5.aspx

c ++查找字符串

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值