Q:

C++ Arrays | Find output programs | Set 5

belongs to collection: C++ find output programs

0

This section contains the C++ find output programs with their explanations on C++ Arrays (set 5).

Program 1:

#include <iostream>
using namespace std;

int main()
{
    char* STR[] = { "HELLO", "HIII", "RAM", "SHYAM", "MOHAN" };

    cout << (*STR + 2)[2];

    return 0;
}

Program 2:

#include <iostream>
using namespace std;

int main()
{
    char STR[5][8] = { "HELLO", "HIII", "RAM", "SHYAM", "MOHAN" };

    cout << STR[2] + 1;

    return 0;
}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer Program 1:

Output:

O

Explanation:

Here we create an array of pointers to store strings. Now, look at the cout statement,

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'.

Answer Program 2:

Output:

AM

Explanation:

Here, we created a program two-dimensional array for strings. Now look the cout statement,

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ find output programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C++ Strings | Find output programs | Set 1... >>
<< C++ Arrays | Find output programs | Set 4...