Variables

VARIABLES

Your resource to C programming

We will begin with a simple program.This is a simple program printing an output on the CONSOLE(Similar screen to MS-DOS).

/* program starts */
#include
main()
{
printf("This is an example.\n");
printf("What is your name.\n"); }
/* program ends */

In the above program #include means to include the library of compiler(The one you are working with) .There are many libraries that provoide many useful functions.Currently we have accessed stdio.h which give us function printf.Observe,that every C statement ends with a semi-colon.A semi-colon tell the program that this is end of a statement and also help in debugging(error free program).It is also worth noticing that every program must have a main(){...} function.why? because In C many separate functions are written and we need to call tham in one place and get our work done within main(). /*..*/comments are written between these which is not seen by the compiler.

/* program starts */
#include
main()
{
int a = 10;
float b = 10.50;
char c = 'a';
printf("%d,%f,%c",a,b,c); }
/* program ends */

Here we have some new terms ,C allows to assign values to names called variables.These variables, we will use to create our programs.Also it is fairly easy to use names than the values itself. Now, we have a new printing format . we will explain that later. How really is this assignment process works? let us see that first. Check the figure below!

The above image gives the correct pictutre about the position of Variable.The memory is consecutive sequence of addresses in which sizeof of int(integer) is 2 bytes ,float(floating point number)is 4 bytes. char(character)is one byte.I assume ,the reader is familiar with the term bits,bytes,etc. There are some other types which we will discuss later,but, these are the types you will be working frequently.

End of Tutorial
1
Hosted by www.Geocities.ws