473,396 Members | 1,884 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,396 software developers and data experts.

C - arrays, getting errors (very simple code)

75
Please tell me why I get errors while compiling my code with GCC =(

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int a[3];
  4. a[0] = 12;
  5. a[1] = 9;
  6. a[2] = 14;
  7.  
  8. int main(){
  9.    printf("%d",a[0]);
  10. }
  11.  
Errors what I get:
test_code.c:4: error: conflicting types for 'a'
test_code.c:3: error: previous declaration of 'a'
test_code.c:4: warning: data definition has no type or storage class
test_code.c:5: error: conflicting types for 'a'
test_code.c:4: error: previous declaration of 'a'
test_code.c:5: warning: data definition has no type or storage class
test_code.c:6: error: conflicting types for 'a'
test_code.c:5: error: previous declaration of 'a'
test_code.c:6: warning: data definition has no type or storage class
Nov 26 '07 #1
3 2309
Meetee
931 Expert Mod 512MB
Please tell me why I get errors while compiling my code with GCC =(

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int a[3];
  4. a[0] = 12;
  5. a[1] = 9;
  6. a[2] = 14;
  7.  
  8. int main(){
  9.    printf("%d",a[0]);
  10. }
  11.  
Errors what I get:
test_code.c:4: error: conflicting types for 'a'
test_code.c:3: error: previous declaration of 'a'
test_code.c:4: warning: data definition has no type or storage class
test_code.c:5: error: conflicting types for 'a'
test_code.c:4: error: previous declaration of 'a'
test_code.c:5: warning: data definition has no type or storage class
test_code.c:6: error: conflicting types for 'a'
test_code.c:5: error: previous declaration of 'a'
test_code.c:6: warning: data definition has no type or storage class

There are some errors in the code like
1) you have to use "using namespace std;" after including header files according to new conventions.

2) return 0 in main()

3) write declaration of a in main() function

Regards
Nov 26 '07 #2
JosAH
11,448 Expert 8TB
You can't initialize an array like that; those are three statements and statements
are not allowed outside function bodies; that's why the compiler whines at you.

Either move those three statements to the body of your main() function or initialize
that array as follows:

Expand|Select|Wrap|Line Numbers
  1. int a[] = { 12, 9, 14 };
  2.  
kind regards,

Jos
Nov 26 '07 #3
dazzler
75
thx for the answers =)
Nov 26 '07 #4

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

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
35
by: Troll | last post by:
Hi, I need to write a script which reads some data and reports the findings. Just to give you an idea the structure is similar to the following. Data input example: HEADING 1 **********...
7
by: csx | last post by:
Hi everyone! two quick questions relating to arrays. Q1, Is it possible to re-assign array elements? int array = {{2,4}, {4,5}}; array = {2,3}
1
by: rir3760 | last post by:
Since a few days ago I have been working with the program I post below (a school assignment). The purpose of the program is to work with the va_ macros (stdarg.h) and arrays of arrays, hopefully...
1
by: Jonathan DeCarlo | last post by:
I have a situation where I need to override a method in managed C++ that was originally defined in C#. The method takes a parameter of an array of arrays of doubles. Here is a simple examples...
6
by: Dennis | last post by:
I was trying to determine the fastest way to build a byte array from components where the size of the individual components varied depending on the user's input. I tried three classes I built: (1)...
5
by: Alan Howard | last post by:
We're getting "ERROR (0x8007000E) Not enough storage is available to complete this operation" errors on a fairly large, busy ASP/SQL Server web site. The error is being thrown on a line calling...
12
by: divya | last post by:
1. If The size of the array is unknown during programming time then how is such array declared?? Suppose there is an Array named arrClashname(size unknown at start), Now when the clash occurs...
6
by: Emiurgo | last post by:
Hi there to everyone! I've got a problem which may be interesting to some of you, and I'd be very grateful if there is someone who can give me some advice (or maybe redirect me to some other place)....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.