Friday, November 8, 2013

Introduction to C language

C is often called a as middle-level computer language. Rather, C is thought of as a middle-level language because it combines the best elements of high-level languages with the control and flexibility of assembly language.

Programming languages are categorized like;
High level
BASIC
COBOL
Pascal
FORTRAN
Middle level
C
C++
Java
Low level
Assembler

As a middle-level language, C allows the manipulation of bits, bytes, and addresses of the basic elements with which the computer functions. Despite this fact, C code is also very portable.
For example, if you can easily convert a program written for DOS so that it runs under Windows 2000, that program is portable.
C Is a structured programming language is commonly referred to simply as a structured language. It has many similarities to other structured languages, such as ALGOL and Pascal.
There are two general methods by which a program can be executed. It can be compiled, or it can be interpreted.
An interpreter reads the source code of your program one line at a time, performing the specific instructions contained in that line. This is the way earlier versions of BASIC language.
A compiler reads the entire program and converts it into object code, which is a translation of the
programs source code into a form that the computer can execute directly. Object code is also
referred to as binary code or machine code. Once the program is compiled, a line of source code is no longer meaningful in the execution of your program.

C Program body looks like this;

Global declarations
int main(parameter list)
{
statement sequence
}
return-type f1(parameter list)
{
statement sequence
}
return-type f2(parameter list)
{
statement sequence
}...
return-type f N(parameter list)
{
statement sequence
}


Compiling a C Program
Creating an executable form of your C program consists of these three steps:
1. Writing your program
2. Compiling your program
3. Linking your program with whatever functions are needed from the library

Example C Program:
#include <stdio.h>
main(void)
{
printf("Hello This is C Program");
}

Save this program as “test.c” then compile & run the program.
Output is: Hello This is C Program
In this program

#include <stdio.h> is global declaration also called as header calls the stdio.h (header file from library)

Main(void) is function used printf statement within { } brackets.

Printf is to print any message within the ( ) brackets and ; (semicolon) is statement terminator.

Let us see another program which accept a value and print it.

#include <stdio.h>

main(void)

{

int n;

scanf(“%d”, &n);

printf(“You entered number is:”, n);

}

Now let us start a C program with name and number

#include <stdio.h>
main(void)
{
int n;
char name[15];
printf("Enter your roll number n");
scanf(“%d”,n);
printf(“Enter your Name n”);
scanf(name);
printf("Your roll number is:"&n”n”);
printf(“Your name is:”, name);
}

In this program I used two variables one is ‘n’ numeric variable and ‘name’ is character variable
Scanf statement accepts values from keyboard.

No comments:

Post a Comment