473,406 Members | 2,698 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,406 software developers and data experts.

int arr[10]; //in file1.c extern int *arr; //in file2.c main() { arr[0]=1; } //

6
int arr[10]; //in file1.c
extern int *arr; //in file2.c
main()
{
arr[0]=1;
}
this code gave error saying undefined reference to arr, why???
Feb 21 '10 #1
1 3720
Banfa
9,065 Expert Mod 8TB
your declaration

extern int *arr;

does not match the definition

int arr[10];

Which is why you should put the declaration into a header file and then include that header into both C files.

In all likely hood the reason you get an undefined reference to arr is either that you only linked with the object from compiling file2.c or that the difference between declaration and definition is somehow causing the linker to ignore the defined array.
Feb 21 '10 #2

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

Similar topics

4
by: F. Da Costa | last post by:
Hi, I was wondering whether someone could enlighten me as to the reason why the slice does not work in IE when the arr is passed in properly. Checked the values in the srcArr and they are...
13
by: Vinu | last post by:
The following code doesn't prints anything why it is? The code is correct. plz explain the logic #include <stdio.h> int arr = {10,20,30,40,50}; #define ARR_SIZE sizeof(arr)/sizeof(arr) ...
17
by: Tapeesh | last post by:
I would like to know what is the expected behaviour of C compilers when an extern decleration is intialized. When the following code is compiled using gcc //File extern.c int arr ; int a ;
10
by: yogeshmk | last post by:
I need to break a longer string (with strtok()) and store the smaller strings in an array. since the number of small strings is not fixed/known, I cannot use a declaration like char *format, so I...
9
by: joshc | last post by:
Hi, I have an array defined in one file with an intializer as follows: int arr = {0, 1, 2, 3}; I have a declaration of the array in another file as follows: extern int arr;
4
by: =?Utf-8?B?cm9nZXJfMjc=?= | last post by:
hey, I have a method that takes a char array of 10. I have a char array of 30. how do I make it send the first 10, then the next 10, then the final 10 ? I need help with my looping skills....
2
by: Christoph Conrad | last post by:
Hi, given the following test case, with CString from Microsofts MFC: ================================================== file 1: CString arr; ...
1
by: arnuld | last post by:
this does not work, i know there is some problem in the "for loop" of "print_arr" function. i am not able to correct the weired results i am getting. i have no compile time error, it is only...
13
by: arnuld | last post by:
this does not work, i know there is some problem in the "for loop" of "print_arr" function. i am not able to correct the weired results i am getting. i have no compile time error, it is only...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.