I wrote little program to print “Hello world” in C. I’m not a C programmer, but I liked to try it. In my program there is an error. Please tell me what is it?
This is my program:
int main(){
printf("Hello World");
}
I wrote this with my Java Experiences. I can’t find what is wrong.
You can’t directly use printf() function as in Java. You should tell the compiler that you are going to use the input/output stream. You can tell it in this line:
and also you should enter this line at the end of the source code:
this will tell the compiler :
This means if your program is successful main() function will return 0. Then the compile know the program is Ok.
Then at last your complete code is:
To compile this and see the word “Hello World”, just save this file as a .c file and Open cmd in your program directory and type
(Replace the ‘hello.c’ with your filename, and ‘hello’ with the name you want to put with your .exe file)
Remember My computer is Windows. And this compile code is for windows. If your OS is UNIX like OS. then use this code to compile: