Hello folks,
I'm working through the section on pointers in my ebook and I decided to try some things out. I'm finding a it a bit hard going though and I've run into a problem. I'm getting compile time errors that I don't understand. I think I have done things correctly and used the syntax correctly but the compiler obviously sees things differently.
I'll post the code and the debugging messages as well. Could someone give me a pointer (pun intended ) in the right direction. Thanks
edit: Sorry. It's supposed to take in 5 intergers from user. These get sent to one function to get the values printed back and to a pointer to each variable and to another function to print the memory addresses of the 5 variables
Code:
#include <iostream>
using namespace std;
void givevalues(int value1, int value2, int value3, int value4, int value5);
void giveaddress(int *p_value1,int *p_value2,int *p_value3,int *p_value4,int *p_value5);
int main()
{
int value1, value2, value3, value4, value5;
cout << "Enter 5 intergers...";
cin >> value1;
cin >> value2;
cin >> value3;
cin >> value4;
cin >> value5;
int *p_value1 = &value1;
int *p_value2 = &value2;
int *p_value3 = &value3;
int *p_value4 = &value4;
int *p_value5 = &value5;
givevalues(value1, value2, value3, value4, value5);
giveaddress(*p_value1, *p_value2, *p_value3, p_value4, p_value5);
return 0;
}
void givevalues(int value1, int value2, int value3, int value4, int value5)
{
cout << "\t\t***VALUES***\n\n";
cout << value1 << endl;
cout << value2 << endl;
cout << value3 << endl;
cout << value4 << endl;
cout << value5 << endl;
}
void giveaddress(int *p_value1,int *p_value2,int *p_value3,int *p_value4,int *p_value5)
{
cout << "\t\t***MEMORY ADDRESSES***";
cout << p_value1 << endl;
cout << p_value2 << endl;
cout << p_value3 << endl;
cout << p_value4 << endl;
cout << p_value5 << endl;
}
/home/neil/Documents/Programming/arrayplay/main.cpp||In function ‘int main()’:|
/home/neil/Documents/Programming/arrayplay/main.cpp|25|error: invalid conversion from ‘int’ to ‘int*’ [-fpermissive]|
/home/neil/Documents/Programming/arrayplay/main.cpp|5|error: initializing argument 1 of ‘void giveaddress(int*, int*, int*, int*, int*)’ [-fpermissive]|
/home/neil/Documents/Programming/arrayplay/main.cpp|25|error: invalid conversion from ‘int’ to ‘int*’ [-fpermissive]|
/home/neil/Documents/Programming/arrayplay/main.cpp|5|error: initializing argument 2 of ‘void giveaddress(int*, int*, int*, int*, int*)’ [-fpermissive]|
/home/neil/Documents/Programming/arrayplay/main.cpp|25|error: invalid conversion from ‘int’ to ‘int*’ [-fpermissive]|
/home/neil/Documents/Programming/arrayplay/main.cpp|5|error: initializing argument 3 of ‘void giveaddress(int*, int*, int*, int*, int*)’ [-fpermissive]|
||=== Build finished: 6 errors, 0 warnings ===|
[/code]