By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,730 Members | 1,659 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,730 IT Pros & Developers. It's quick & easy.

please find the error in this program

P: 1
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. main ( )
  3. {
  4.     int i = 1;
  5.     int *p=&i;
  6.     q=p;
  7.     int *q = 5;
  8.     printf("%d \n",*p);
  9. }
Dec 7 '19 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 162
A variable cannot be used before its declaration.
Dec 8 '19 #2

Expert 100+
P: 2,401
Also, main must return int.
Dec 16 '19 #3

Expert 100+
P: 162
If the return type is not specified, it is implicitly declared as int.

According to C99 rationale (
A new feature of C99: In C89, all type specifiers could be omitted from the declaration specifiers in a declaration. In such a case int was implied. The Committee decided that the inherent danger of this feature outweighed its convenience, and so it was removed. The effect is to guarantee the production of a diagnostic that will catch an additional category of programming errors. After issuing the diagnostic, an implementation may choose to assume an implicit int and continue to translate the program in order to support existing source code that exploits this feature.
From C99 or later, warnings are likely to be generated: "-Wimplicit-int" (

On testing the above code with TDM-GCC 4.9.2 64-bit Release, no warning was there.

With GNU GCC, "warning: return type defaults to 'int' [-Wimplicit-int]" -> likely targeting the C99 or later version.
Dec 17 '19 #4

Post your reply

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