Flag This Hub

Some basic computer programming concepts and variable declarations

By


In computer programming, there are certain steps that every programmer should complete before they actually start the writing or coding process of the program. One of the first things that I suggest that you do is write down what is called pseudocode. Pseudocode is basically short phrases written in English and these phrases describe the algorithm of the program that you are working on. An algorithm is a series of instructions that are written which enable the programmer to complete a specific task or to solve a problem in a finite amount of time. Some programs will take longer than others to complete depending upon their complexity. Pseudocode makes everything easier because when you write pseudocode before you start coding, you have a better general idea of what steps to take to complete the program. I would like to consider pseudocode as the blueprint of the program. When you start writing the pseudocode, you can use the symbol /*. And then, when you are finished with that part, you can end the pseudocode section with the symbol */. Pseudocode and comments are ignored by the compiler.

Writing comments during the coding process of the program gives other programmers a better idea of where the program is going. It helps make your program more readable. Programmers can then understand what you are doing. When a programmer is busy coding and writing the program, it is their responsibility to be able to come up with an algorithm that solves the task correctly and efficiently. Just compiling the program is not good enough. You also must run the program to make sure that it displays the output that you would like to see on the screen. If you run the program and then you see that it does not display the correct output on the screen, this is where a logic error can occur. Getting the program to run efficiently and display the correct output is very challenging because when you write the program, you have to have a solid general idea of the concepts that you are using to complete the task. And it takes lots of practice to learn the concepts in C++, Java or any other programming language. In other words, to say this in more simple language, in order for your program to be complete, it must compile properly and be free of any syntax errors and it must also run correctly and display the proper output on the screen. Do not think that just because your program compiles correctly then it is done and complete. Your program must do both steps just described. Every method or function as they are known in C++ must have a main function.

After you have declared the main function in the program, you can write a comment saying that you want to declare the variables. A variable is something that has a name and that it describes a certain value. But first you must assign a specific data type to the variable. Some examples of variable declarations are:

int 56;

double 50.00;

float 34.5;

char letter;

A variable can always be changed during the execution of a program unless you decide to declare the variable as a named constant. If you decide to declare the variable as a named constant, then it cannot be changed during the execution of a program. A variable name cannot begin with any numbers, special characters such as a dollar sign, number sign or exclamation point. A variable name also cannot have one of the reserved key words of the programming language such as while, return or do-while. And another thing to remember is that when you declare a variable make sure to do it using lowercase letters.

When you declare your variables in your program and assign values to them, make sure that you write the value after the name of the data type. For example, you cannot declare a variable like this: 25 = int;

If you do it that way, you will get a syntax error. So make sure to declare the variable and assign the value like this instead: int = 25;

And as always, do not forget to put the semicolon after the variable has been declared and assigned the value. A lot of programmers make this mistake. But as you get better at programming, you will make fewer errors.

Comments

No comments yet.

Submit a Comment
Members and Guests

Sign in or sign up and post using a hubpages account.



    Like this Hub?
    Please wait working