Header Ads

First C program:C Programming Language - Part 1.2

First C program


Programming requires a computer and a compiler. Before writing the first program we do not know about a few topics. Such as compiler, text editor etc.

Compiler:

C is General Purpose, Structured Programming Language. Computer or any machine can only understand 0 or 1. Which we call binary number system If we ask to write programs in binary, we can not write easily. We write the program, we can understand ourselves, in such a way. In C programming we can understand the code, such as printf, if, else, for, 1 + 2, etc. We need a program to make them into machine language, which we call the compiler The compiler makes the code written by us in the machine code. Then the machine can easily execute those codes.




One of the advantages of C programming is that the code can be compiled directly into the machine code. And so it is very easy to write code for the machine, the operating system can be created.

Text editor:

We usually write code in a text editor. Many of you may use Microsoft Word or a Word processor. The difference between word processor and text editor is that whatever we write in the text editor, its source code will be there. What we write in the word processor, it encodes its own way. Your computer has the default text editor. Such as textpad on windows.



We can write our code to any text editor. Extension of C programming .c. Then we can run our code as a .c file, such as hello.c, and run through the compiler.

IDE or Intergraded Development Environment:

IDE is a software like Microsoft Word Processor. Many of them work together. For example, code can be written. Compiler with it is integrated. Code can be run directly from IDE. Again if we write a wrong code IDE can catch mistakes and let us know before compiling it. If there is a mistake after writing a program, why IDE might also be incorrect.

After writing the code in the text editor, it will be difficult for them to learn new programs, then run the program in the compiler. So we will use an IDE when writing our program.



There are different IDEs for each programming language. Another codec can be written in multiple programming languages. CodeBlocks is a great IDE for writing C programs. We will use CodeBlocks IDE for writing and compiling C code. If you want to download CodeBlocks, you can download it at http://www.codeblocks.org/downloads web site.



Go to the download section of the codeblocks website and go to the download binary release section. You need to download the operating system accordingly. There are separate download sections for each operating system.

When downloading, be sure to download it with mingw. Mingw is the compiler. If you do not download CodeBlocks with compller, the program will not run. The codeblocks-xx.0xmingw-setup.exe file will have to be downloaded. Here xx is any number. The codeblocks regularly releases new versions, so this number will change.



After download, you have to install it. Install any kind of software that is installed as you would like it to be installed.



In addition to CodeBlocks there are many IDEs for writing C programs such as Visual Studio, Xcode [for Mac], Eclipse with CDT etc.

Writing C program in Android Phone or Tab:

If you have an Android device, you can also run and write C programs. Go to the Google Play Store and install the CppDroid-C / C ++ IDE app and write this App C program. You can see the output run by typing. There are many more examples in this app. You can learn a lot by watching them see them.


First C program:


We will use CodeBlocks IDE for writing and compiling C code. To download CodeBlocks, download the codeblocks-12.11mingw-setup_user.exe at the following link.

Http://www.codeblocks.org/downloads/binaries

Then install. Once installed, you are ready to write code. Open. Then you can see the following.





From there click on create new project.or you can create a new project from menu in file>new>project.to create a new project ,you will see many options as follows


From here, select the Console application and click on Go.

select programming

Now select C and click Next. Enter your project's name in Project Title box. As hello Select the folder where you want to save your project from a folder to create project in box. Click on Next. Now click on Finish.

Now you will see your workspace on the right. Your projects will show up here. Click on the + sign of hello. Then click on the + sign of the source and click on main.c CodeBlocks will create a simple code template, for each project. Which will be written in

1
2
3
4
5
6
#include <stdio.h>;
Int main ()
{
    Printf ("Hello world!");
    Return 0;
}
For us to compile and run the code, from the File menu, click Build and click on Build and Run. Then your C program will be compiled and run. And give the output as below:
c++ program

The window that shows the result is called console. When we select the project, we have selected the Console Application. So our output showed in the console. The program that we will create in this book, all of which will be the console application.



The above program can be discussed. Print means printing or showing some of the consoles. Printf means print function. Now the question is, what is the function again? There is a full chapter named Function. We'll know the details there. Now just know about printf. He writes in a printf, so he looks at the console. We wrote in printf Hello World! And so we have seen the consoles.

Now in the printf you see something else. Then run the program and see. See what you do not write, the program shows it. Great You've got to write your first program beautifully. That's the beginning. Get a new way.



From today you are special. Because you know programming. There are many ways to go ahead. You have to learn a lot. One day you can learn to learn a lot of great software. Can create a game. You can write a robot program. And those who have created the operating system, who have created software for robots, who created Google, Facebook program, Hello World! Started with



Explanation of the Hello World program:




Let us now explain a bit more about what we are writing in the above code. If you feel difficult, you can easily start the second chapter. They can understand them slowly.

The first line of our program is #include <stdio.h>. Include means adding something. Stdio is the full width of standard input output. Stdio.h stands for. This is a header file. And the whole line implies that the standard input output is connected.



The next line is int main (), it is called main function. The main function will start working when we run the program. So all programs have to have a (and simply a) main function. The start of the main function is to start with the second bracket. The main function is to finish with a second bracket.
We write the first line inside the main bracket of the main function, we printf ("Hello world!");
Here printf () is a function. Printf means print formatatted. This is a library function called standard output function. The printf () function is printed on the console / screen. It will print whatever we write inside the double quote sign. We first write a line that #include <stdio.h>. The printf () function is printed on how to print it and it is written in the stdio.h file.



After this we are writing another line return 0; We're saying that main is a function. Every function has to have a return value of the function. Which returns a few returns at the end of the function's function. Return 0 means zero return. Further details can be found later when we will read the functions.



Printf ("Hello world!"); Or return 0; These are called Statement. At the end of each statement in C programming, one semicolon (;) is to be given. If we do not do the semicolon, then the compiler will look incorrect and the program will not run. At the beginning of the programming, many people forget to enter the semicolon, then compile error, then try to find out where the mistake was made. If you write the code carefully, these minor mistakes can easily be avoided.



If you run the code above the codebalk that was created when running the above program, then first remove all the code. Then type yourself again from start to finish and run it. Hello World! Write any other text instead. Like own

Problems and Solutions:


Code block is an IDE. It takes our compiler with it. Which will compile our C programs. If the compiler is not installed, it will show an error like below.

Environment Error Can not Fild Compiler Executable in Your Config Search for "GNU GCC" compiler


For this we need to download and install with Codeblocks with Mingw. If you download and install the codeblocks-x.x.x mingw-setup.exe file in the download page, the problem will be solved.






No comments

Theme images by sebastian-julian. Powered by Blogger.