Start Programming

Discussion in 'C / C ++' started by Butta381, Mar 22, 2018.

  1. Butta381

    Butta381 New Member

    Hello there;
    I guess everyone who has a computer called C and C ++ has heard it at least once. If you are one of those who hear these names and you are looking for answers to many questions, such as what is, what is not, how to use it, you are in the right place. Because starting with this article, we will enter programming with C and C ++ . We first go to C with our path, and after reaching a certain degree we will continue with C ++ . ​

    I thought it was more accurate to take the most basic of the book, thinking about the general of our readers. So our goal is to reach a certain place where a person who never knows how to program is reading here. If they are advanced, they should wait a bit to get bored. Let's start without overdoing it. ​

    What is Computer and Programming?​

    The computer is a machine that performs three main tasks when we think it is very simple. It receives input information (INPUT) , processes (PROCESSING) and this processed result (OUTPUT)It pulls. The computer will not function only as hardware. Because without the software, the hardware does not know what to do. It requires a sequence of commands to tell the computer what to do. We can schedule the tasks that he will perform, the commands that tell him. So the hardware is the job of the program or, in other words, the software, to do things like "you do it, then the end result is". Of course, knowing more than that as a programmer is an advantage. But you do not need to know all the features of the computer. So you will not know the properties of that computer for a program. ​

    The only language the computer understands is Machine Language. This 16 (Hexadecimal)system is a type of programming. It is very difficult to understand the machine language and in order to use this language you absolutely must know the hardware features of that computer. In C , a very simple function like "printf ();" that allows you to write on the screen becomes much more complex and meaningless in the machine language like 1A BB 0D BC D5 FF C2 F7 .... The machine language is the lowest level among programming languages. ​

    After the machine language comes the Assembler Language . Assembler developed on the difficulty and complexity of using machine language, is a simpler structure. But still, it is much more difficult to compare with C and you still need information about the hardware of the computer you are using. The assembler is a complex structure as follows.​

    Code:
    SEGMENT COM WORD PUBLIC 'CODE'
    ASSUME CS: COMDS: COM
          ORG 100H
    ENTRY: MOV DVX, OFFSET MSG
           MOV AH, g
              .
              .
              .

    Do not waste your time trying to figure this out. Because the language C we learn will make our work and therefore our life much easier. C is an intermediate programming language. This means that you are both easy to write and have more access than high-level languages. The top programming languages are BASIC, PASCAL, and so on. In higher tongues, writing is relatively easier, but with C we can do more.

    What do you need to write a program?
    You do not need anything to write a program. You can use Windows's notepad to write programs, or even a program like Gedit, Kwrite in Linux. The important thing is the compilation of the written program. Compilation to "compile" and that if the compiler to compile business "compiler"It called. For C you can find many Compilers over the internet. I will do program applications through GCC . I would recommend setting up this compiler in the same way. As GCC is one of the best compilers ever, it is free software! It is provided by Richard Stallman in an open source code and if you so desire, you are allowed to make changes to the end.

    If you have a Windows operating system , installing GCC may be a bit daunting. With a simple Google search, I found a program called Bloodshed Dev-C ++ . It had a structure based on GCC . Windows users who do not want to deal with GCC can try this program.​


    Developing Algorithms
    Learning C language and its commands is essential to start programming, but you will not create a program unless we can create an algorithm. Algorithm is logic. So it tells you what to do and how to do it. There is no method developed to derive the algorithm. You have to find that method for each program. But do not worry, as the number of programs you write increases, it becomes easier to set up the algorithm.

    The algorithm is the backbone of programming. Commands used in C language do not work in other languages such as BASIC or FORTRAN . But once you have the programming logic, you can learn commands from other languages, instead of the C commands, and you can write programs in other languages without major difficulty.

    Let's think through a simple example. You went to a markete, you showed the product you bought in the bus, you extended the money, you took the money. You can change this situation which is quite normal in daily life. You are not an individual, but an electronic cashier. If we develop an algorithm according to him,​



    1-) Look at the product;
    2-) Find product price;
    3-) Take the money;
    4-) Take out product price from buyer;
    5-) Give the remaining money.​



    Unfortunately, the computer does not know the actions of human intelligence and we have to teach him. We have no right to make mistakes while teaching, because wrong teaching results in incorrect programming.


    C Programming Language

    Basic Input / Output Operations (BASIC I / O):

    With regard to C, we will see a lot of commands / functions in this and the following text. But we will always use it and the first things we need to learn are the basic input / output functions. In C, you can use scanf () to get a value from the keyboard ; function. To print anything on the screen, printf (); function is used.

    According to an example;​


    Code:
    #include <stdio.h>
    int main (****)
    {
        printf ("Hello World");
    }
    If you write this in your compiler and run it afterwards, Hello World will be written on the screen. #include <stdio.h> carries the meaning of including the standard input / output header file, programa. Including a library in C (and almost all other programming languages) is a very routine activity. Otherwise, we have to define the input-output functions from the beginning, even each time.
    main () is the main function in a program. The separator after that is standard. It represents a block. The area between the two parentheses marks forms a block of the main function. printf is a standard function that prints the text we print on the screen. Everything you print with double quotes is printed on the screen with printf .​

    If you are careful, we put a semicolon at the end of each line. In fact, it is more accurate to say we put a semicolon after each command, not every line. Because semicolon means command delimiter in C language. ​

    Now the simple program we wrote above, let's improve it a bit:​

    Code:
    #include <stdio.h>
    int main (****)
    {
        printf ("Hello World \ n");
        printf ("Hello World");
        return 0;
    }
    You see a few new lines. Let us explain in turn what they are. We just added "\ n" to the end of the "Hello World" we just wrote . "\ n"means a sub-line is late. If we do not type "\ n" , the screen will display "Hello WorldMerhaba Dünya". If we use "\ n" , after "Hello World" is written, a sub-line is passed and "Hello World" is printed on the second line. At the bottom "return 0;" You have noticed a new command named. If you do not add this, the program will still work; but gives warning. Because the main function expects an integer return. You can get rid of these warnings with the return statement we wrote.

    We could write the same program as above:​



    Code:
    #include <stdio.h>
    int main (****)
    {
        printf ("Hello World");
        printf ("\ nHello World");
        return 0;
    }
    The programs that we wrote before and now are the same as the screen output. With this example, I'm going to put a '^ n' in the printf () function , followed by a subscript.

    Code:
    #include <stdio.h>
    int main (****)
    {
        printf ("Hello World \ nHello World");
        return 0;
    }
    As you can see, a single printf (); using the same process. ​

    Suppose we had to write a very long sentence on the screen. For example;​


    Code:
    #include <stdio.h>
    int main (****)
    {
        printf ("My name is MaskHacker and Software Engineer. \ n");
        return 0;
    }
    Although this program does not produce an error, it reduces the efficiency of the operation. Because if your writings do not fit in the editor window, it would be more difficult to read them. It may sound like a trivial detail, but you can be sure that the efficiency of writing code will drop dramatically.

    It is better to write this program as follows:

    Code:
    #include <stdio.h>
    int main (****)
    {
        printf ("My name is"
            "Maskhack is"
            "and Software Engineer. \ n");
        return 0;
    }
    A single printf (); function is used. However, by writing the bottom line, we have made the text visible only once. If you compile and run the program, the bottom line is not written three lines. The sentence is shown in its entirety and is exactly the same as the previous example. (We wanted to see the lines appear in the bottom line, we had to put '\ n' as we mentioned before.)

    Displaya, Ali: "Naber, how are you?" said. Let's say we need to print a letter. We will have a small problem in this regard. Because printf (); The function treats the first two double quotes. To print something like this on the screen, we need to write a program like this:​

    Code:
    #include <stdio.h>
    int main (****)
    {
        printf ("Ali: \" Naber, how are you? \ ") \ n");
        return 0;
    }
    printf (); I think you will understand how to use the function. printf ( typing, then open double quote, it says what you want to write, double quotes after the parenthesis closes, we are adding a semicolon. Although intra move to the bottom line, write what we end the '\ n' , we add. Double quoted a thing possible internal use \ "... \ " we use. that's all!

    scanf (); when it comes to function, our input as we mentioned this at the beginning (input) function is our. But writing here, I conclude. Because the variables are introduced into the business and take a long time to tell them. we will continue from where we left in writing next week. Summer Homepage about If you have suggestions, criticisms or problems, you can contact me.

    Continue to arrive shortly. I expect your comments.



     

Share This Page