Saturday 18 January 2014

making first program 'Sum'

Now we write our first program with C. Our program is use to compute the sum of 10 and 20. It is a basic program to understand the little things that including the programming language. We taking three variable as x, y and z.

x=10
y=20
z=x+y



The sum should be 30 but how it works in program and how to write ? Before this we have to learn what is it ?

Rule


Here x,y and z are variable and its value 10 and 20 is constant. = and + are arithmetic operators for performing a particular operation.


Before using any variable in program we must declare first. To declare a variable means to specify type of information and the most important thing that all variable which is declared in a function can alive in its own function. We give an example to understand this all rule.

The following are the basic and most important keyword for declare variable/data type.


Data/Info Name of Data type Keyword Format specifies
1,554,78 etc Integer nm int %d
2.54 ,5.5887 etc Fractional/real nm float, double %f
O,A,c,l,e etc Character char %c


Note: All the statements within a function should be terminated by semicolon ';'. Because of semicolon rule C language is also called as free form language.



Our first Program



int main()
{
int x,y,z;
x=10;
y=20;

z=x+y;
return 0;
}


The above program is our first program. The first line int main() is a function named as main(). Without main() function program not work. int is a return type used because this is an integer based program and it will return an integer value. We can also use void instead of int  when we write void we don't have to write return 0 because void is not return value.

After function we must write all of his code in block of codes, block of codes means between opening curly braces and ending curly braces

Next we declare three variable x,y and z and the data type of every variable is int ,int can store 32 bit of memory. Because of declaration memory will allocate in ram for these three variable. It will send request for allocation of memory send to Operating System.
consider that above rectangle is ram and here allocation for x, y and z is done, while variable x, y and z are int type so it can hold only 4 bytes/32 bit. Means that in small rectangle of  x , y and z only 4 byte or less value can be place.

In next line x=10 and y=20 the assignment for variable x and y is done. means the box/rectangle of x is now holding the binary number of 10 and y is holding binary number of 20. In statement z=x+y four steps are take place first the value of x is picked up second the value of y is picked up third the addition of the value of x and y will proceed and the last step is the addition of x and y is assign to z in binary form
 

Note : The above program has no output. Because we had not use printf() function. In my next post I will describe predefine function and header files.

Friday 17 January 2014

Chapter 1 Grammar of Programming Language

Learning programming language We first learn about its grammar. I know that you don't hear about grammar of programming language but its matter. Before making program we first think like a machine because the program that we make is run by a machine like calculator,computer and other digital machine which is compatible. Basically grammar of programming languages is just guideline and limitation. Here we will talk about C programming language and its grammar.


Keyword/Reserved word of C


Just think why people don't named his pet as If, You, They, Me, I, To, We, Us...
Because it is a grammatical result. In programming languages some word are already reserved and that is not use as identifier. This reserved word is called as Keyword. There are many keywords of C languages and we can not use this word as identifier. C is a case sensitive language. All keywords of C are write in lower case



List of Keywords of C


continue    goto        sizeof         volatile
default     if          static         while
do          int         struct         _Packed
auto        else        long           switch
break       enum        register       typedef
case        extern      return         union
char        float       short          unsigned
const       for         signed         void
double

  the highlighted keyword are basic and most important kayword


What is role of Keyword ?


Keywords are reserved word in C and every keywords have its unique behavior when we apply it in our program. When we talk about every language we use many grammatical such that in programming this keyword act as a grammatical word. Here we define only those keyword that we use in our program. The next grammatical part is Function.



What is Function  ?


The function is very little part of program or you can say function is Sub-Program. Actually function is group of statement/instruction for doing particular work. When we make program we have to write some codes again and again because of this the time and complexity of program is increase and short sized programs are become large. Function play important role in programming without function you can't done. There are two type of function C such as predefine function (Built in functions) and User defined function. I will describe function in my post letter.

Thursday 16 January 2014

Basic of Computer Programming



There are different types of programming languages with the help of this programming language we can make a program. Generally a program is a set of instruction.
Before making any program we first learn the basics of computer system and programming.



What is a Program ?


I have already described you about program in my first post introduction. Human language compare to the Programming language is very different. Computer or digital machines are work on when an operation is done. Suppose we know English language but the computer does't know the English language. It only know the machine language (1,0). This is work as instruction for a machine.
Programming languages helps us to give instruction to the machines in his language while we don't know the machine language.



How to make program ?


Computer/digital machine have its own memory but it do not have sense. Computer can do only those work that is instructed by programmer/users. Programs are the the sense for computer to do a particular work. If we want to create a program we must keep in mind every condition/instruction (flow chart) that will occur in real life.
MS Word, Notepad, WordPad are editors. With the help of this editors we can not make a program. If we want to write a program we need a GCC Compiler. In this compiler we first write source codes than compile it and we get a compiled code. Here the source code is write in simple programing language while the compiled code is change to machine code. This machine code is execute by the Operating System.



Dos/Windows/Unix/Linux are Operating System


There are many Operating System such as Windows xp,7,8,vista, Unix, Linux, mack, backtrack etc. This operating System Operate the system. We can use more than one operating system in a computer but in a particular time only one operating system can operate the computer.When Program is execute than operating system run the program. Programming language use to make the program, Compiler used to compile the program and when compiled code get executed the operating system run that  program


User Interface


Now we know basic of programing. This time you are reading this post in a computer or other any device this is called User Interface. When something get printed on screen/monitor it known as user interface. if only text get printed than it is known as Text User Interface and if the text and graphics/rectangle window with color both get printed on monitor than it is known as Graphic User Interface. The TUI and GUI is depends on hardware and operating system of a particular device.
Think before 7 years calculators are best way to calculate and this have only Text User Interface. But now days you have a mobile with Text User Interface and Graphic User Interface.

Interface: When any object use the feature of another object than it is known as Interface. With the help of User Interface we communicate with machines.



Difference between program and software


It is simple to define A software is containing many programs. Software is collection of programs. The graphical user interface, text mode user interface, coding, little functionality and many more items are containing by a software but a program is only one part of software.

Wednesday 15 January 2014

Programming Introduction

hello friends i am introducing very simple concept to learn programming language. If you read all of my post you will definitely become a good programmer. If you are familiar with the other programming languages then you have to no problem about the basics of programming but for those who are new in  this field i am giving simple tips and concept for easy learning programming.




What is program in programming language ?


The programs are set of instruction that is used for complete a work in very short time. before 1980's there is no programming languages, no software, no programs and programmers and the easy work was become complex. Now days you just complete most of work without headache in very short time.
The program are useful for anyone who are using technology. Without programming the program is like a body without mind.




How should Program help us ?


Very simple, before the programming languages are not develops the work become complex.
(before) Suppose you are the worker of an company and you come to office daily. A man sitting on receptionist. You go there and he write your attendance in a black register with time . When you leave the office he again write your name and time.

(now) This time your company gives you a card introducing your identity. You come to the office and go to door and swipe this card in an machine on the door than the door automatically open. Your attendance and time is automatically reached on data base. Same process when you leaving the office.
In the second approach there is no need of man and register. In the second approach the time and money is also save.

When you swipe your card to the machine the machine get a instruction and it will watch for a unique number. If the unique number is existing than it will open the door and get your name and a paticular time for check in. That is the power of program....

There are many programing languages. With the help of this programing languages we can make programs.Programming language is medium between computer system and programmer.