473,320 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

static declaration in functions follows non-static declaration

#include <stdio.h>
int main()
{
int n=20;
int A[n], B[n], C[n];
int addarrays (int add1, int add2, int counter);
int i;
for(i=0; i<n; i++)
{
printf("%d", addarrays(A[i], B[i], i));
}

int addarrays (int add1, int add2, int counter) //defining function
{
C[counter]= add1 + add2;
printf("%d", C[counter]);
return C[counter];
}
}

I am trying to create a function that adds elements of arrays in a specific way (for uni) but i get the error that was in the title.
Dec 26 '11 #1
4 10471
weaknessforcats
9,208 Expert Mod 8TB
You are defining the addarrays fnction inside main().

Plus you are using main()varaibles directly insde the function.

!) write your function ouside main()
2) pass main() variables to the function.
3) inside the function use the argumwnt variables only.
Dec 26 '11 #2
lspxy
12
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. #define N 20
  4.  
  5. int C[N];
  6. int addarrays (int add1, int add2, int counter); // declare function
  7.  
  8. int main()
  9. {
  10.  
  11.     int A[N], B[N];    // A[], B[] should be initialed before used.
  12.     int i;
  13.  
  14.     for(i=0; i<n; i++)
  15.     {
  16.         printf("%d\t", addarrays(A[i], B[i], i));
  17.         printf("\n");
  18.     }
  19. }
  20.  
  21. int addarrays (int add1, int add2, int counter) //defining function
  22. {
  23.     C[counter]= add1 + add2;
  24.  
  25.     printf("%d", C[counter]);
  26.  
  27.     return C[counter];
  28. }
  29.  
Jan 2 '12 #3
weaknessforcats
9,208 Expert Mod 8TB
This:

Expand|Select|Wrap|Line Numbers
  1. for(i=0; i<n; i++)
  2. etc...
should be:
Expand|Select|Wrap|Line Numbers
  1. for(i=0; i<N; i++)
  2. etc...
Jan 2 '12 #4
lspxy
12
yea, so careless. thanks.
Jan 3 '12 #5

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

Similar topics

2
by: Rahul Joshi | last post by:
Hi, Is it possible to define static member functions that are 'const', i.e. they just read but do not modify the static data members of a class? Declaring functions like: class SomeClass {...
5
by: Naren | last post by:
Hello Grp, Correct me if I am wrong. static member functions can act only on static member varaibles.It can accessed by using the name of the class. Then why is there an access controller. ...
3
by: exits funnel | last post by:
Hello, One of the problems at the end of Chapter 14 in Bruce Eckel's thinking in C++ reads as follows: Create a class with two static member functions. Inherit from this class and redefine...
11
by: Roger Leigh | last post by:
The C++ book I have to hand (Liberty and Horvath, Teach yourself C++ for Linux in 21 Days--I know there are better) states that "static member functions cannot access any non-static member...
3
by: qWake | last post by:
The C++ language standard stipulates at section 9.4.1 that " A static member function shall not be declared const " The question is: what problem(s) could possibly exist in allowing static...
1
by: RainerFaulstich | last post by:
Hi, Some dummy question : Are static member functions of a class indeed a single instance for all instances of the class or have difference instances of this class have its own instances of this...
3
by: paul.furber | last post by:
Hi all, I have some code which looks a bit like this: #define Offset(m, T) ((size_t)(&((T *)1)->m) - 1) class Point: private: int *x,*y;
15
by: Philipp | last post by:
Hello I don't exactly understand why there are no static virtual functions. I would have liked something like this: class Base{ static virtual std::string getName(){ return "Base"; } }
32
by: lcdgoncalves | last post by:
Hi everyone Is there a real need to use keyword static with functions, if we simply don't declare their prototypes in .h file? Many textbooks avoid to discuss this matter and/or discuss only...
6
by: Olumide | last post by:
Hi - I've got a class that contains static member functions alone, all of whose arguments are passed by reference as shown below: class MySpiffyClass{ // no constructor, destructor or...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.