EmbLogic's Blog

Errors in “Hello World” program

#include<stdio.h>
int main()
{
printf(“Hello World”);
return 0;
}
/* Errors
Line 1 :-
*1. If u remove only preprocessor (#)->error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
*2.#nclude<stdio.h> ->  error: invalid preprocessing directive #nclude
*3. #include -> error: #include expects “FILENAME” or <FILENAME>
*4,5 #include<  -> error: missing terminating > character
#include<>    error: empty filename in #include
#include<stdio.h  -> 4th error
*6. #include<stdio> -> fatal error: stdio: No such file or directory

Line 2 :-
*7. int main(  -> error: expected declaration specifiers or ‘…’ before ‘{’ token
*8. int main   -> error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
*9. in main()  -> error: unknown type name ‘in’
*10. int main(*) -> error: expected declaration specifiers or ‘…’ before ‘*’ token
*11. int main(‘) ->  error: missing terminating ‘ character
*12. If no main() -> error: expected identifier or ‘(’ before ‘{’ token

Line 3 :-
*13. if no {  -> error: expected declaration specifiers before ‘printf’
error: expected declaration specifiers before ‘return’
error: expected declaration specifiers before ‘}’ token
*14. ..{  -> error: expected ‘{’ at end of input
*15. {..  -> error: expected expression before ‘.’ token

Line 4 :-
*16. printf(“Hello World”). -> error: expected identifier before ‘return’
*17. printf(“Hello World”) -> error: expected ; before ‘return’
*18. printf(“Hello World”) -> error: expected ‘)’ before ‘;’ token
error: expected ‘;’ before ‘}’ token
*19. print(“Hello World”)  -> undefined reference to `print’
*20. print(Hello World)  -> error: ‘Hello’ undeclared (first use in this function)
*21. print(“Hello World)  -> warning: missing terminating ” character [enabled by default]
error: missing terminating ” character
error: expected expression before ‘return’
error: expected ‘;’ before ‘}’ token
Line 5 :-
*22. return c; -> error: ‘c’ undeclared (first use in this function)
Line 6 :-
*23. missing } -> error: expected declaration or statement at end of inpu

*/

/* Warnings

w1. If u remove header -> warning: incompatible implicit declaration of built-in function ‘printf’
*w2. #include<stdio.h> -> warning: extra tokens at end of #include directive [enabled by default]
*w3. return NULL       -> warning: return makes integer from pointer without a cast

*/ Special Case :-
/* ; -> You can freely put ; or ;; anywhere in main (before fn., after fn., blank line etc.)
*      Except you can’t put ; after main();
*      ;int main() -> Valid
*      {; ->         Valid
*      }; ->         Valid
*      printf(“Hello World”);; -> Valid
*    Shows warning if used after #include<stdio.h>;
*/

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>