Two lines in the codes below have been remarked out else compiling would fail:
//arrcon[1]=*scon;
//count << "arrcon[1] " << arrcon[1];
The intention was to assign character values to an array with 5 elements, each with a maximum 35 characters, declared as a string array, arrcon[5],[35];
I was trying to use pointer, but there must be bug/s somewhere. It did not work. See codes below.
Kindly point out where I went wrong.
// pointers Use of pointers to assign values to a string array
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <string>
#include <stdlib.h>
using namespace std;
int main ()
{
string arrcon[5][35];
string* scon;
string name;
string xcon;
name="YBY";
scon=&name;
xcon=*scon;
cout << "\nname = " << name;
cout << "\nscon= mem add. of name: " << scon;
cout << "\nxcon= value of name: " << xcon << "\n\n";
// Now using array
//arrcon[1]=*scon;
//count << "arrcon[1] " << arrcon[1];
// use of pointers courtesy of http://www.cplusplus.com/doc/tutorial/pointers/
cout << "\n\nUse of pointers courtesy of http://www.cplusplus.com\n\n";
int numbers[5];
int * p;
p = numbers; *p = 10;
p++; *p = 20;
p = &numbers[2]; *p = 30;
p = numbers + 3; *p = 40;
p = numbers; *(p+4) = 50;
for (int n=0; n<5; n++) {
cout << "\t" << numbers[n] << ", ";
}
cout << "\n\n";
getch();
return 0;
}