Pointer and Arrays

Hey guys and gals, I'm have to do an assignment where I use pointers delete the second array value but every time I try to use a pointer it will give me the "[Error] invalid conversion from 'int' to 'int*' [-fpermissive]"

The function delete_second is suppose to delete the second number in the array.

The swap_First_Last is suppose to delete the first number in the array.

Are teacher made up the names and problems so that's why some of these are weird.

#include <iostream>
#include <cstring>
using namespace std;

void print(int Array1[], int n)
{
for (int i=0; i<n; i++)
{
cout << Array1[i] << endl;
}
cout << endl;
}
void delete_second( int * & list, int & size )
{
int *x=list[1];

delete x;
list++;
size--;
}



void addElement( int * & list, int & size, const int value )
{
int * newList = new int [size + 1];

for( int i = 0; i < size; i++ )
newList[ i ] = list[ i ];

newList[ size ] = value;
size++;
list = newList;
}

int* swap_First_Last(int *&Array1, int n)
{
int* newList = new int [size-1];
for(int i=0; i<size-1; i++)
newList[i] = list[i+1];
delete [] list;
size--;
}

int main()
{
int n;
cout << "Enter in how big you want your array to be (go from 2 and up for best results): ";
cin >> n;

int *Array1 = new int[n];
if(n<=0)
{
cout << "bad size" << endl;
return 0;
}
cout << endl << endl << "Enter in values for the array: \n";

for (int i=0; i<n; i++)
{
cin >> Array1[i];
}

cout << "1st Print." << endl;
print(Array1, n);

cout << "Adding Element." << endl;
addElement(Array1, n, 77);
print(Array1, n);

cout << "Deleting Element." << endl;
delete_second(Array1,n);
print(Array1, n);

cout << "Swap Thing." << endl;
swap_First_Last(Array1, n);
print(Array1, n);

delete [] Array1;
return 0;
}
int *x=list[1];
This line causes a compiler error.
You're gonna get a ton of errors. One after one.

First, int *x = list[1]; should be int *x = list.

Second, in your function int* swap_First_Last(int*&, int) you didn't declare size.
Topic archived. No new replies allowed.