Search This Blog

Friday, March 30, 2012

Constants and Variables-Constants


Constants

The C language is composed of seven basic types of code: Constants, Variables, Operators, Punctuations,
Keywords, Functions and Labels – collectively known as Tokens.

A constant is a named storage location in the memory where the compiler keeps unchanged data during program execution. Constants are of two types: Literal Constants and Symbolic Constants. A literal constant is a value that is directly used in the source code wherever it is needed.

E.g. int max = 100; integer constant
float tax = 0.05; floating point constant.
float multiplier = 2.03E-2 floating point constant (in scientific notation)

Integer constants can be written in three different notations.

  1. An integer constant starting with any digit other than 0 is treated as a decimal integer. It can contain a leading + 
  2. A constant starting with a 0 is treated as an octal integer. It can contain a leading + 
  3. A constant starting with a 0x or 0X is treated as a Hexadecimal integer. It can contain digits from 0 to 9 the letters A to F and a leading + or -.

Comments in a Program


Comments in a Program

Any text that you enter between /* and */ is considered to be a comment and is ignored by the compiler.

White Space Characters

The characters - space, Tab, Carriage Return (CR), Line Feed (LF) and Back Space are considered to be white space characters and they will be ignored by the compiler.



printf() Function

The printf() function is one of the most widely used functions in C. The purpose is to output its argument list to the standard output device. All the characters within a pair of double quotes will be treated as a string constant
except for escape sequences and conversion specifications.

Saturday, March 24, 2012

Directives in a Program


Directives in a Program

A directive is a special statement that can control the features of a compiler.
E.g.

a) #include <stdio.h>

provides a convenient way of telling the compiler that all the I/O functions have been included.

b) #include <math.h>

provides the standard math library.

c) #define

defines a symbolic name or a constant.

Thursday, March 8, 2012

Stages in Creating a C program


Stages in Creating a C program


1. Designing

2.Coding

You must first create a file which contain the C source code. For this you may use any text editor. The file name could be any legal name accepted by the DOS / UNIX and must have an extension of C.
E.g. pro1.c


The source code that you enter must obey the structures, the syntax and semantics of the C language.

3.Compiling

The C compiler receives the source code from the pre-processor and translates it in to assembly code.

 4.Assembling

The assembler creates object code. In MS-DOS the object files are seen with .obj extension


5.Linking

If a source file references library functions defined in other source files, the link editor combines these functions with main() to create an executable file (.EXE)


Saturday, March 3, 2012

Structure of a Function


Structure of a Function


Function name (parameters)
{
local variables ;
statements ;
}

The Minimum C Program

main()
{
}