Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
#include <iostream.h>
#include <conio.h>
void main()
{
void sum(int []={5,8});
sum();
 
getch();
 
}
void sum(int x[])
{
for(int i=0;i<=2;i++)
cout<<x[i];
}
 

I use array as default arguments but my program have lot of errors
Posted 19-Feb-13 0:35am
ALIWAZ407
Comments
Maximilien at 19-Feb-13 8:34am
   
Default arguments are evil, more so for "complex" data like vectors/arrays.
 
DON'T USE THEM.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

#include <iostream>
#include <conio.h>
 
using namespace std;
 
void sum(int x[])
{
    for(int i=0;i<2;i++)
        cout<<x[i];
}
 
void main()
{
    int values[] = {5,8};
    sum(values);
    getch();
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid