Writing Our First C Program
Now when we are ready with our C Compiler let’s try our hand in some simple coding to start with.
This is just a simple program in which I will just print a simple message or statement.So just have a look at it:
I have used “# include
“main()” is a function which the c compiler first look for.What is a function I will tell you later in this course.
Inside the main() function I used the “printf()” function to display the simple message “This is Our First Program”
“return 0” means that the function main() returns zero or nothing.
After finish coding I saved my file as “program1.c”,you can save your file with any name of your choice with .c extension.
After saving my file I compiled my file using the command
gcc –o program1_obj program1.c
In the above command I use “-o program1_obj” to give the name my object file a name.You can give any name of your choice just after the “– o” followed by name of your c program (i.e. in this case program1.c)
After finished compiling I run my c program using the command
“./program1_obj”
i.e. “./” followed by name of the object of that c program file.
Congrats !!! Done.
If you are windows user and you are using any of the three compilers then to compile and run your program by just remembering these keys
Dev C++
F9 -To Compile and Run
Turbo C++
Alt+F9 – To Compile
Ctrl+F9 – To Run
If you have any confusion just let me know.
Thanks!!!