C Tutorial Part 1- Hello world!

C Tutorial Part 1-Hello World (Print statement)

Hi, this is Cercomp's official blog website.

This is tutorial for beginners to create their first C application and to save and compile it.

There are a few requirements to complete before starting out-

A code editor program- (C free 5 or 4 is recommended) but others will also do.
Click on this link to download C free 5 from my secure Google Drive link-https://drive.google.com/file/d/1PQ6rH7yHJIHdgMrQxfAUdn7MC5P2LJlW/view

C-free will tell you to purchase a license after 30 days of usage.
To get a free license code, take a look at this post-https://cercomp.blogspot.com/2019/03/c-free-5-professional-free-license-code.html

Mingw C/C++ compiler- Used to compile programs in an executable format after they are written. Example (.exe).
Download it from its official website link- https://osdn.net/projects/mingw/releases/

So let's get started now.

1. Open C free 5 or your other code editor.
2.Click on new blank file.




3. Type # <stdio.h> . <Stdio.h> is the header file and it basically enables the computer to perform some functions. There are many header files. A few examples are <iostream>, <stdlib.h>, and <conio.h>(They will be explained later on different posts). All of these header files allow some or the other functions to occur. And don't worry, as we can put as many header files we want in our program to make it multitasking.




4. Type - int main (){

This is compulsory statement to write in C and your application will not work without it.
It creates an area in your computer's memory where all the functions of your program take place. the () represents 0 which will be used to close your program. { is the starting bracket to where your main program begins. There will be a } (closing bracket ) at the end of the program where your program finishes. If you are using c free 5, then two brackets will be made an you will write your code in the middle.



5. Type the syntax- printf ("Hello World\n");

The syntax printf displays text on the screen. Text which has to directly displayed is written under ("....."). The brackets are used for variables(explained in the next blog) so don't worry about them now. Hello World is to be printed and this code,'\n' is used to leave a line and as C always displays press any key to continue after your program's function finishes. And you do't want 'Hello WorldPress any key to continue' to appear on your screen. You can always use the exit (0) syntax to avoid this but there will be many posts till I explain that(bit advanced). The semicolon in the end(;) is used to declare that a function is over.




6. Type the closing command - 'return 0;'
This command returns the value of zero and closes the functional area of the program. There should be the closing } after this function.
PS : The semicolon is there as it is also a function.





7. Now go to File menu and click on the save option-


8. Select the search box to where you want to save your file and save it as whateveryouwant.cpp-
(it's better saving your file in the .c++ format to avoid bugs and to have better usage capabilities of graphics and functions)



9. Now after your file is saved, go to Build and compile your code-
(Make sure to have Mingw installed)




10.
Now your piece of code has been compiled and is saved as an .exe file.

Now you can run your application by pressing run on the build window.



11. Congrats, you have your desired application-




12. You can now run your application from the place where it is saved.




If you have any queries, go to-
https://cercomp.blogspot.com/p/cercomp-contact-info.html




Comments

Post a Comment

Popular Posts