C langugae : Data Types

C89 defines five foundational data types: character, integer, floating-point, double floating-point, and valueless. These are declared using char, int, float, double, and void. Variables of type char are generally used to hold values defined by the ASCII character set.The basic data types may have various modifiers preceding them. A type modifier alters the meaning of the base type to more precisely fit a specific need ie signed, unsigned long, short

A C program processes data into meaningful results. All C programs include the following:
• Commands
• Data
Data is made up of variables and constants. A variable is data that can change while the program runs. A constant remains the same. In life, a variable might be your salary. A constant would be your first name or social security number, because each remains with you throughout life and does not (naturally) change.
A C constant is any number, character, word, or phrase ex:- 5.6, -45 , 'Q', "Mary", 8.67643
Local Variables
Variables that are declared inside a function are called local variables. In some C literature, these variables are referred to as automatic variables.Local variables can be used only by statements that are inside the block in which the variables are declared.Local variables exist only while the block of code in which they are declared is executing. That is, a local variable is created upon entry into its block and destroyed upon exit.A variable declared within one code block has no bearing on or relationship to another variable with the same name declared within a different code block.
void func1(void)
{
int x;
x = 10;
}
void func2(void)
{
int x;
x = -199;
}
The integer variable x is declared twice, once in func1( ) and once in func2( ). The x in func1( ) has no bearing on or relationship to the x in func2( ).
Global Variables
Global variables are known throughout the program and may be used by any piece of code. Also, they will hold their value throughout the program's execution. You create global variables by declaring them outside of any function. Any expression may access them, regardless of what block of code that expression is in.
#include
int count; /* count is global */
void func1(void);
void func2(void);
int main(void)
{
count = 100;
func1();
return 0;
}
void func1(void)
{
int temp;
temp = count;
func2();
printf("count is % d", count); /* will print 100 */
}
void func2(void)
{
int count;
for(count=l; count<10; count++)
putchar('.');
}
Notice that although neither main( ) nor func1( ) has declared the variable count, both may use it. func2( ), however, has declared a local variable called count . When func2( ) refers to count, it refers to only its local variable, not the global one. If a global variable and a local variable have the same name, all references to that variable name inside the code block in which the local variable is declared will refer to that local variable and have no effect on the global variable. Global variables are helpful when many functions in your program use the same data.
High Level Language : - Ada, Modula-2, Pascal, COBOL, FORTRAN, BASIC
Middle Level Language : - Java, C++, C , FORTH, Macro-assembler
Low Level Language : - Assembler
All high-level programming languages support the concept of data types. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common data types are integer, character, and floating-point. Although C has several builtin data types, it is not a strongly typed language, as are Pascal and Ada. C permits almost all type conversions. For example, you may freely intermix character and integer types in an expression.
C is special in that it allows the direct manipulation of bits, bytes, words, and pointers. This makes it well suited for system-level programming, where these operations are common.
Another important aspect of C is that it has only a small number of keywords, which are the commands that make up the C language. For example, C89 defined 32 keywords, and C99 adds only 5 more. High-level languages typically have many more keywords. As a comparison, consider that most versions of BASIC have well over 100 keywords!

C langugae : Seven Steps

Seven Steps of C Programming
Step 1: Define the Program Objectives
Step 2: Design the Program
Step 3: Write the Code
Step 4: Compile
Step 5: Run the Program
Step 6: Test and Debug the Program
Step 7: Maintain and Modify the Program

Compilers vs. Interpreters

There are two general methods by which a program can be executed.
* Compiler
* Interpreter
The compiler is a special program that reads the instructions stored in the source code file, examines each instruction, and then translates the information into the machine code understood only by the computer’s microprocessor.
* The compiler translates the information in the source code file into instructions the computer can understand. The linker then converts that information into a runnable program.
* The GCC compiler recommended and used in this book combines the compiling and linking steps. An object file is created by GCC, but it is automatically deleted when the final program file is created.
* Object code files end in OBJ or sometimes just O. The first part of the object file name is the same as the source code filename.
*Feel free to cheerfully forget all this object code nonsense for now.
*Text editor - Compiler.
*Source code - Program.
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 worked.
Object code is alsoreferred 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.In general, an interpreted program runs slower than a compiled program. A compiler converts a program's source code into object code that a computer can execute directly.

Library and Linking

All C compilers come with a standard library of functions that perform most commonly needed tasks.Standard C specifies a minimal set of functions that will be supported by all compilers.
When you call a library function, the C compiler ''remembers" its name. Later, the linker combines the code you wrote with the object code already found in the standard library. This process is called linking. Some compilers have their own linker, while others use the standard linker supplied by your operating system.
The functions in the library are in relocatable format. This means that the memory addresses for the various machine-code instructions have not been absolutely defined— only offset information has been kept. When your program links with the functions in the standard library, these memory offsets are used to create the actual addresses used.

A Simple Example of C

/* comments: - To print Message */
#include < stdio.h >
#include < conio.h >
main( )
{
printf("hello");
getch( );
}

C : Compile Process

The compiler is just a way to transform your program from a source code file to an executable file.The program must go through one additional stage after compiling and before running. It is called the linking, or the link editing, stage your program is linked, the compiler sends runtime information to your program such as the memory addresses where variables and code will be stored when your program executes. You can also combine several compiled programs into one executable program by linking them. Most of the time, however, your compiler initiates the link editing stage and you do not have to worry about controlling the linking process.

The executable results of a source program that ends with the .C extension. Again, be as accurate as possible. In most programming languages—and especially in C—the characters you type in a program must be accurate. In this sample C program, for instance, you see parentheses, ( ), brackets, [], and braces, {}, but you cannot use them interchangeably.
The comments (words between the two symbols, /* and */) to the right of some lines do not need to end in the same alignments that you see in the listing.

C : Precedence of C operators

The following table shows the precedence of operators in C. Where a statement involves the use of several operators, those with the lowest number in the table will be applied first.

Description Represented By
1 Parenthesis ( ) [ ]
1 Structure Access _ ->
2 Unary ! - ++ -- - * &
3 Multiple, Divide, Modulus * / %
4 Add, Subtract + -
5 Shift Right, Left >> <<
6 Greater, Less Than, etc > < =
7 Equal, Not Equal = = !=
8 Bitwise AND &
9 Bitwise Exclusive OR ^
10 Bitwise OR |
11 Logical AND &&
12 Logical OR ||
13 Conditional Expression ?:
14 Assignment = += -= etc
15 Comma ,


Free Web Hosting