expected out put is not coming

1
2
3
4
5
6
7
8
9
#include <stdio.h>
int a =1
int a;
int main()
{

	printf("%d\n",a); // expected 0 but o/p is 1 why ? 
	return 0;
}


1
There's an error at line 2, the code does not compile because of a missing semicolon.
Also there's an error, int a is defined twice, on lines 2 and 3.
... along with a missing ; on line 2.
Sorry guys semicolon is there , It compiles fine and give ouput also
1
2
3
4
5
6
7
8
9
#include <stdio.h>
int a =1;
int a;
int main()
{

	printf("%d\n",a); // expected 0 but o/p is 1 why ? 
	return 0;
}


Please let me know why so wrong output
Last edited on
I can't get this to compile as C++. I get an error
[Error]Multiple declaration for 'a'
or
[Error] redefinition of 'int a'

However, when compiled as C instead. it does seem to compile.
I'm not sure of the rules here, and how the two languages differ. I could guess (but that isn't useful).
I found this article, which seems relevant:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka16744.html

The important concept seems to be that of the tentative definition. A search for that term will bring up more information.
tentative definitions are also covered on cppreference here: http://en.cppreference.com/w/c/language/extern
Topic archived. No new replies allowed.