473,507 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

function declaration

3 New Member
#include<iostream.h> #include<iostream.h>
#include<conio.h>
#include<math.h>

void display()
int main()
{
int a=9;
int b=10;
clrscr();
cout<<display(a,b)<<"\n";
return 0;
getch();
}
void display(int A[] [],int m, int n)
{
int i,j;
for (i=0;i<m;i++)
for (j=0;j<n;j++)
cout<<" "<<A[i][j];
cout<<"\n";
}

i have listed my program to call a function above but it is showing an error as below in line 5 called ' Declaration syntax error'

kindly help me solve this
Jul 20 '07 #1
10 1984
Meetee
931 Recognized Expert Moderator Contributor
#include<iostream.h> #include<iostream.h>
#include<conio.h>
#include<math.h>

void display()
int main()
{
int a=9;
int b=10;
clrscr();
cout<<display(a,b)<<"\n";
return 0;
getch();
}
void display(int A[] [],int m, int n)
{
int i,j;
for (i=0;i<m;i++)
for (j=0;j<n;j++)
cout<<" "<<A[i][j];
cout<<"\n";
}

i have listed my program to call a function above but it is showing an error as below in line 5 called ' Declaration syntax error'

kindly help me solve this
You have define and declare same function with different parameters!!! I am pointing to void display()

Regards
Jul 20 '07 #2
joeschnell
47 New Member
Yeah, I'm just starting CIS247 and went through functions briefly but, he is right on the paramaters. When you declare your function within the () you need to list the same paramaters as you use below in your code using the & before repeated use declarations.

functions (one, &two, three, four, &five, six)

int main ()

...
...
...
..now you call it
functions (here you need to call out the parameters the same as above)
(one, two, three, four, five, six)
Your code seems pretty sophisticated to not know how to call a function. Hope you get it. Joe
Jul 20 '07 #3
joeschnell
47 New Member
void display (int, &double, &double, &char, int, double)


when calling

void display (int, double, double, char, int, double)

or close to that--later
Jul 20 '07 #4
magnacarta
3 New Member
void display (int, &double, &double, &char, int, double)


when calling

void display (int, double, double, char, int, double)

or close to that--later


hi Joe, thanx for the help i made the changes but it shows 2 errors now.
1. size of the type is unknown or zero and 2. declaration is expected

i m pasting the program again with my changes

#include<iostream.h> #include<iostream.h>
#include<conio.h>
#include<math.h>
void display(int A[] [],int m, int n,)
int main()
{
int a=9;
int b=10;
clrscr();
cout<<display(a,b)<<"\n";
return 0;
getch();
}
void display(int A[] [],int m, int n)
{
int i,j;
for (i=0;i<m;i++)
for (j=0;j<n;j++)
cout<<" "<<A[i][j];
cout<<"\n";
}

kindly b patient as i have just started learning C++ and am doing it on my own with aid from you guys and this site
Jul 21 '07 #5
Meetee
931 Recognized Expert Moderator Contributor
hi Joe, thanx for the help i made the changes but it shows 2 errors now.
1. size of the type is unknown or zero and 2. declaration is expected

i m pasting the program again with my changes

#include<iostream.h> #include<iostream.h>
#include<conio.h>
#include<math.h>
void display(int A[] [],int m, int n,)
int main()
{
int a=9;
int b=10;
clrscr();
cout<<display(a,b)<<"\n";
return 0;
getch();
}
void display(int A[] [],int m, int n)
{
int i,j;
for (i=0;i<m;i++)
for (j=0;j<n;j++)
cout<<" "<<A[i][j];
cout<<"\n";
}

kindly b patient as i have just started learning C++ and am doing it on my own with aid from you guys and this site
Hi magnacarta,

Again you check your code. You are calling display with two parameters and function is defined/declared with 3 parameters. You can define array locally in display function as you are just printing the value locally.

Regards

PS. Kindly put code tags around code
Jul 21 '07 #6
archonmagnus
113 New Member
Just for comparison:
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>  // removed trailing ".h"
  2. #include<conio.h>   // careful, this is a Windows only library!!!
  3. #include<cmath>     // changed from "math.h" to "cmath"
  4.  
  5. // old declaration: notice there is a comma after 'n'
  6. //    and no semicolon at the end of the prototype
  7. // void display(int A[] [],int m, int n,)
  8.  
  9. // new function prototype
  10. void display (int a, int b);
  11.  
  12. int main()
  13. {
  14.     int a=9;
  15.     int b=10;
  16.  
  17.     // ...stuff before function call...
  18.     cout<<display(a,b)<<"\n";
  19.     // ... stuff after function call...
  20. }
  21.  
  22. // old declaration
  23. //void display(int A[] [],int m, int n)
  24. void display (int a, int b)
  25. {
  26.     // ...stuff in function...
  27. }
  28.  
Or if you still need the array, then the function call is the part of the code that needs to be edited. i.e., you'd need to add the array to be passed to the function.
Jul 21 '07 #7
anubhavit
5 New Member
#include<iostream.h> #include<iostream.h>
#include<conio.h>
#include<math.h>

void display()
int main()
{
int a=9;
int b=10;
clrscr();
cout<<display(a,b)<<"\n";
return 0;
getch();
}
void display(int A[] [],int m, int n)
{
int i,j;
for (i=0;i<m;i++)
for (j=0;j<n;j++)
cout<<" "<<A[i][j];
cout<<"\n";
}

i have listed my program to call a function above but it is showing an error as below in line 5 called ' Declaration syntax error'

kindly help me solve this

The error in the program is that you are not passing the 3 arguments that you are making use of in the function. Change the display function to
void display(int m, int n)
{int A[3] [3];
int i,j;
for (i=0;i<m;i++)
for (j=0;j<n;j++)
printf("%d",A[i][j]);
printf("\n");
}
and your program should work
Jul 21 '07 #8
magnacarta
3 New Member
The error in the program is that you are not passing the 3 arguments that you are making use of in the function. Change the display function to
void display(int m, int n)
{int A[3] [3];
int i,j;
for (i=0;i<m;i++)
for (j=0;j<n;j++)
printf("%d",A[i][j]);
printf("\n");
}
and your program should work
i made the changes as to my understanding but not there is an error 'Declaration syntax error' in line 5. could some one kindly make this program error free put it here. sorry but thanx
Jul 22 '07 #9
weaknessforcats
9,208 Recognized Expert Moderator Expert
void display(int m, int n)
{int A[3] [3];
int i,j;
for (i=0;i<m;i++)
for (j=0;j<n;j++)
printf("%d",A[i][j]);
printf("\n");
}
You have nested for loops but no braces:
Expand|Select|Wrap|Line Numbers
  1. for (etc...)
  2. {
  3.       for (etc...)
  4.       {
  5.  
  6.       }
  7. }
  8.  
Also, the array is a local variable so there is no way to get values in the array from main(). Did you mean to do that??? Or did you mean to create the array in main() and then call the function to display the array?? I thinkl you still have a logic problem.
Jul 22 '07 #10
phiefer3
67 New Member
hi Joe, thanx for the help i made the changes but it shows 2 errors now.
1. size of the type is unknown or zero and 2. declaration is expected

i m pasting the program again with my changes

#include<iostream.h> #include<iostream.h>
#include<conio.h>
#include<math.h>
void display(int A[] [],int m, int n,)
int main()
{
int a=9;
int b=10;
clrscr();
cout<<display(a,b)<<"\n";
return 0;
getch();
}
void display(int A[] [],int m, int n)
{
int i,j;
for (i=0;i<m;i++)
for (j=0;j<n;j++)
cout<<" "<<A[i][j];
cout<<"\n";
}

kindly b patient as i have just started learning C++ and am doing it on my own with aid from you guys and this site
Magnacarta, so far in every one of your posts, you also forgot the ; at the end of your prototype in line 5:

void display(int A[] [],int m, int n,)

should be

void display(int A[] [],int m, int n,);
Jul 22 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

14
2079
by: dover | last post by:
/*Copy the line a token at a time into the output*/ copy(istream_iterator<string>(iss), istream_iterator<string>(), ostream_iterator<string>(oss, " ")); What's the meaning of this statement?...
10
15037
by: Phil Reardon | last post by:
Ive been away from programming for a few years and am having difficulty accessing a function from a math/engineering library that I want to use . I thought that double foo(double); inserted in the...
6
1407
by: feminine.aura | last post by:
I have to read a file containing integers into a vector. I could do something like this: ifstream data("file.dat"); istream_iterator<intbegin(data); istream_iterator<intend;...
4
6089
by: nospam_timur | last post by:
Let's say I have two files, myfile.h and myfile.c: myfile.h: int myfunction(int x); myfile.c: #include "myfile.h"
1
1890
by: INeedADip | last post by:
What is the difference between: function setupGrid( param ){......} and setupGrid = function( param ){......} Are there any advantages to doing one over the other?
1
1325
by: wtu | last post by:
function Declaration&Definition -------------------------------------------------------------------------------- " Geroty (const vector<Point3D>& poly, const Plane& Tr)" As i'm c++ beginner...
1
2024
by: Lawrence Spector | last post by:
Base base; BaseWrap& baseWrap(reinterpret_cast<BaseWrap&>(base)); boost::python::object obj(boost::shared_ptr<BaseWrap>(&baseWrap)); // Compile error Results in this error: ...
4
1773
by: florian.loitsch | last post by:
I wondered what should be the result of the following code: === function f() { x = false; function x() {}; alert(x); } === According to Ecmascript-spec we have the following rules: 10.1.3:...
29
8050
by: Ravishankar S | last post by:
Dear C Experts, While prepating a content for a C course,I made section on function prototypes. Could you kindly provide me your comments on its correctness. Thank you ! Q12: What is the...
13
1946
by: Sri Harsha Dandibhotla | last post by:
Hello all. I recently came across a function declaration as : char(*(*x()))(); This was not in some code but it was in a C questions thread on some group. I tried to decipher what it returns but...
0
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7029
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.