Got some problem with arrays!!!
hello guys can you help me out with this problem i mean why cant i use the function par in cout command????
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include<string>
#include<iostream>
using namespace std;
void par(int ar[],int lgt)
{
for(int i=0;i<lgt;i++)
{
cout<<ar[i];
}
cout<<"\n";
}
int main()
{
int n[]={1,2,3,4};
cout<<"haha atlast it happened"<<par(n,4);
}
|
You're attempting to print out a
void function, which is only going to give you an error.
Cout will print values, but will not call your functions for you. Par needs to be called on a separate line by itself:
1 2 3 4 5 6
|
int main()
{
int n[]={1,2,3,4};
cout<<"haha atlast it happened";
par(n,4); //call function
}
|
another note, C++11 make the '=' arbitrary for array brace initialization so you are able to leave that out.
Last edited on
Topic archived. No new replies allowed.