Geeks With Blogs
Daily dotnet {notes on codes}

The typical program of Hello World in c is somewhat like


#include <stdio.h>


To compile in linuc, we use

cc HelloWorld.c

and to run


The output of the program is

hello, world

Now in Page 6, chapter1, we have two exercises

Exercise1-1 : Run the "hello, world" program on your system. Experiment with leaving out parts of the program, to see what error messages you get.

Lets do it,

First, we comment the line  #include <stdio.h> like //#include <stdio.h>

we get a compile time error like

HelloWorld.c:5: warning: incompatible implicit declaration of built-in function ‘printf’

hence we conclude that the printf function comes from the library <stdio.h>, which is responsible for standard input/output.

Secondly, we comment the function main() like //main(), we get a compiler error like

HelloWorld.c:4: error: expected identifier or ‘(’ before ‘{’ token
which implies that every program must have a main function, hence that. Also the return type of the main funtion is interger, hence if we specify it as void, we get the compiler error like

HelloWorld.c:6: warning: ‘return’ with a value, in function returning void
HelloWorld.c:4: warning: return type of ‘main’ is not ‘int’

But if we specify the return type as int, it compiles successfully.

*the environment used during the exercise was Linux and the compiler is gcc.

Please post more information if you feel. Thanks


Posted on Wednesday, March 3, 2010 8:17 AM C Sharp | Back to top

Related Posts on Geeks With Blogs Matching Categories

Comments on this post: Deeper into Hello World

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Prasenjit | Powered by: