Hi guys, starting from C language lesson1: Introduction to The C programming language, today i'm resuming with the second lesson in C language programming. I'm keen on making it so simple for you to understand well.
So at first you have to download any program/compiler for C language, such as: Turbo C++, Visual C, Pelles C.. etc.
well, in this tutorial we're gonna use Turbo C++.. you can download it from turboc8.
Turbo C++ |
After downloading, install the program by clicking next, next, finish as usual. then Open the program by clicking on its icon on Desktop, then a window will appear, you can minimize it by click Alt+Enter, the program will be a stuff like this
Turbo C++ interface |
now as you can see, there are some menus facilitate the use of the program, and you'll know the use of each of them in each lesson gradually.
Now, you are looking at the simplest possible C program. There is no way to simplify this program, or to leave anything out. Unfortunately, the program doesn’t do anything.
main()
{ }
The word "main" is very important, and must appear once, and only once, in every C program. This is the point where execution is begun when the program is run. We will see later that this does not have to be the first statement in the program, but it must exist as the entry point.
The two curly brackets {}, properly called braces, are used to define the limits of the program itself.
simple, isn't it ? - well, there are also some helpful files when creating a new program that can be added at the first statement in the program like this:
#include<stdio.h>
these files can be divided into three types:
1. introduction files: text files that contain orders/messages for the compiler.
2. library files: a group of sub programs that are already compiled to do specific jobs. i.e. printf().
3.mathematical library: contains a number of specific programs to do the sums.i.e. sqrt().
Declaring variables in C
The variable can be defined as a place in the memory, within the values are stored so that the program can easily deal with them, and these values can be changed while running the program.
the declaration take a form like this
int x;
where; int is the variable type and x is the variable name.
and you must consider the following in naming the variable:
1. the variable name must begins with a character, not a number.
2. the variable name mustn't include any labels (i.e. +,-,?,>..etc)
3. there's a difference between a variable written in CAPITAL WORDS and small words.
- ex: int b; (small)
- int B; (CAPITAL)
b (small) is a variable and B (CAPITAL) is another one, even if they were written in the same program.
Before i end this lesson, i want you to know the variable different types as shown:
- int x; (for integer numbers), containing 2 bytes place to store integer numbers, like x=5;
- float y; (for floating point numbers stored in memory in 4 bytes space/place, like y=25.34;
- char ch; (for storing only one character in 1 byte, like ch='d'; the character must be put between semi quotation as you see 'd';"
- char *name; (for storing a place for name variable to store names/a set of series characters, and the names/characters are put between double quotation as you can see "Eidarous";
How to put a value in a variable
there are two methods to put a value in a variable:
1. in the start of declaring the program, which is called initial value.
for example
int x=5;
float z=2.05;
char n='d';
char *str="Eidarous";
2. anywhere in the program:
for example
x=-2;
z=5.5;
Now, i guess you know enough details to be ready for the next lesson, so try to understand every word in this lesson, 'cuz this lesson is the base to the upcoming lessons. Stay tuned and share this page with your friends on Facebook, twitter.. etc.
Don't hesitate to ask me anything in the comment form below
and Don't forget to Like us on Facebook and Subscribe on Youtube
0 التعليقات:
إرسال تعليق
كُن إيجابياً .. ضع تعليقك :