Showing posts with label C help. Show all posts
Showing posts with label C help. Show all posts

Tuesday, May 20, 2008

C Programming Language



Header File:-

Saturday, May 17, 2008

How to open C program code window

How to open C program code window

Before opening C on your computer. Please ensure that C compiler has been loaded or not. If not then please load it first and then try any of the following ways to open C which suit your computer setting.

1.Start>>Program >> Turbo c.

2. If turbo C icon is present on your computer desktop then simply click on it.

3. My computer >>c:\>> tc (folder)>> bin (folder) >> tc.exe (icon).

4. Or make sure the path where you have loaded the C on your computer and try to run it from there.

Description of C code window


Description of C code window

1. =: Interface to external programs.

2. File: File related option such as opening and saving file.

3. Edit: Cut,Copy,Paste operation.

4. Search: Find,Find & Replace operation.

5. Run: Compile and run the file currently loaded in the text editor. And debugging such as setting/clearing trace points can be performed from this menu.

6. Compile: The menu item compiles a source file to an object file or an .exe file.

7. Debug: Provides interactive debugging. Variables can be examined/set/cleared, and we can watch variables change during execution.

8. Project: This menu item controls Borland C++'s handling of large programs that are in multiple source file.

9. Option: Default option are set during installation . The user can change any option at any time through this menu.

10. Windows: Windows operation include zoom, arranging windows on the screen , and closing windows.

11. Help: Borland C++ includes a context sensitive help capability. Select Help or press f1 for general Help, Shift f1 for indexed help or Ctrl f1 for context sensitive help.

Saving and Running a program

Saving and Running a program

Press Alt F, move the cursor to save , press Enter and then type file name with extension .C in given Text Box and press Enter to save the program.

Running a program

Press Alt R to pull down the Run menu and Enter to begin compilation, A compile window opens and shows progress and output can be viewed in output window and press Alt W to pull down window menu, move the cursor down to output and press Enter. Press Alt W and move the cursor to close to close output window immediately.

Exiting Borland C

Press Alt X to Exit Borland C and return to Dos Prompt.

The components of C language

The components of C language

There are five main component of C language are:

1. The character set: Any alphabet ,digit or special symbol ,used to represent information is denoted by character. The character in C are grouped into four categories.

1 Letters A...Z and a...z
2 Digits 0,1,2,.....9
3 Special Symbol ~,`,!,@,#,$,%,^,&,*,(),.,<,>,?,/,",:,;,{},[]
4 White Space blank space, Carriage return, form feed, newline, horizontal tab

2. The data types: The power of the programming language depends, among other thing, on the range of different types of data it can handle.

3. Constants: A constant is a fix value that doesn't change while program execution.

4. Variable: A variable is an entity whose value can change during program execution.

5. Keywords: Keywords are those word which have been assigned specific meaning in C language. Keywords should not be used as variable names to avoid problem.

Note: Above given all the term has been discussed in details in next section.

Structure of C Program

Structure of C Program

Every C program is made of function and every function consist of instructions called statement.

Structure of C Program.

#include //stdio.h is the header file
main() // main function is the first function which is executed by a C program.

All C statements are written within main function.
{

// All C statements.

}

Functions

Every C program consists of one or more modules called functions. One of the functions must be called main( ).
The program will always begin by executing the main function, which may access other functions.

Any other function definitions must be defined separately, either ahead of or after main.

A function name is always followed by a pair of parenthesis, namely, ( ). And all function statements are enclosed within a pair of braces { }.

The program execution always starts with main function. When the closing brace of the main function is reached, program execution stops, and the control is handed back to the OS (Operating System).

Statements

Single C language instruction is called a statement. Statements are written according to the grammar of C language. Every C language statement must ends with semicolon(;).

In order to write a C program we should follow some basic rules which are described below:

a) Usually all statements in C are entered in small alphabets.

b) Blank spaces may be inserted between two words to improve the program readability. However no blank spaces are allowed within a variables, constants or key words.

c) It has no specific rules for the position at which statements is to be retained that's why it’s often called a free form language.

d) All C statements must end with a semicolon (; )

Till now, We have very little knowledge about the type of variables, constants and key words. Now we would try to understand the simple C program.

Read this artical regarding C -
1.Introduction(C character set, identifiers, and keywords, data types, )
2.The C character set
3.Key words In C
4.Introduction(Data types)
5.Primary Data Type
6.Secondary Data Type
7.Introduction(Variable)

Friday, May 16, 2008

Key words In C

There are certain reserved words, called keywords, which have standard, predefined meanings in C.

These keywords can be used only for their intended purpose; they cannot be used as programmer-defined identifiers.

Some standard keywords are:

auto extern sizeof break floatn static case for char

switch register return long int else while short void

Some C compilers may recognize other keywords.

Note that the keywords are all lowercase. Since uppercase and lowercase characters are not equivalent, it is possible to utilize an uppercase keyword as an identifier.

Normally, however, this is not done, as it is considered a poor programming practice.

Secondary Data Type

1. Array:

It is a collection of data of similar data type.
e.g. Int num [5];

Reserve a sequence of 5 location of two bytes each for storing integers.

2. Pointer:

Pointer is a variable that stores the address of some other variable.
e.g. int *i;

The above statement declares i as pointer to integer data type.

3. Structure:

A structure is a collection of data of different data types under one name.
e.g.
Struct employees
{
char Name[10];
int Age;
int Salary;
}

4. Union:

It is a collection of data of different types sharing common memory space.
e.g. Union item

{
int m;
float x;
char c;
} ;

5. Enumerated Data types:

This data types gives us an opportunity to invent your own data type and define what values the variable of this data type can take.
Example: enum colors

{
red, green, blue, cyan
};
colors foreground, background;

Here the declaration has two parts:

a) The first part declare the data type and specifies its possible values.
b) The second part declare variable of this data type.

Now we can give the values to these variables:

foreground=red;
background=blue;

But remember we can't use values that aren't in the original declaration. Thus, the following declaration cause error.

foreground=yellow;

Note: Secondary data type has been given in detail later.

Rules for constructing variables names

Rules for constructing variables names

There are some specific rules for constructing variable names in C language:

(a) Variable name may be a combination of alphabet digits or underscores and its lengths should not exceed 8 characters, some compilers allow 40 characters also.

(b) The first character must be an alphabet.

(c) No comma, blank spaces are allowed in variable name.

(d) No special symbols except underscore can be used as variable names.

Variable declaration

Variable declaration

All the variables must be declared before their use. It does two things:

(a) Tell the compiler what the variable name is.

(b) Specify what type of data that a variable will hold.

Syntax of variable declaration:

data_type variable_name;

Example of variable declaration:
int i,j,k;
char ch;

Assigning values to variables

Assigning values to variables

To assign values to the variables, assignment operator (=) is used.

Syntax of assigning values:

variable declaration;
Variable_name = value;

Example of assigning values:

Int i , j;
j = 5 ;
i = 0 ;

It is also possible to assign a value at the time of declaration.
e.g.
int i = 5;

More than one variable can be initialized in one statement using multiple assignment operators.

e.g. j = m = 2;

There could be an exception while using multiple assignment operators.

e.g. int i , j = 2 , k;

here the assignment will be i = 0 j=2 and k = garbage value

Scope of variables: LOcal and Global

Scope of variables: LOcal & Global

Scope of variable means where the variable stands in the program. All variables may not necessary be available to all statements in a program.

Variables can have two types of scope:

a) Local:

When a variable is declared inside the function then such a variable is known as local variable.

A local variable can only be accessed by the function in which it is declared. It cannot be accessed by other function.

b) Global:

A variable which is declared outside all functions is known as global variable.

A variable with a global scope is accessible to all the statements in the program. A global variable can be accessed by all the functions.

Wednesday, May 14, 2008

Constant in C(introduction)

All Constant in C(introduction)
Introduction

There are some values which do not change during the execution of the program. These values are called constants.
Constants are of fixed value that remain unchanged during the execution of a program, and are used in assignment of statements. Constants are stored in variables.

Syntax of constant declaration:

Const datatype var_name = value;

Example of Constant declaration:

Const int a = 5;

In C language there are five types of constants which has been described separately

Character constants

Character constants

A character constant consists of a single digit or a single special symbol enclosed within a pair of single inverted commas. The maximum length of a character constant can be 1 character.

e.g. --> 'a', 'i' , '5', '='.

There are some character sequence constants which are used in C to represented special action, these are called C Escape Sequence.

List of these escape sequence and its tasks are given below:

\a : audible bell

\f : form feed

\r : carriage return

\v : vertical tab

\' : single quote

\? : question mark

\HHH: 1 to 3 digit hex value.

\b : backspace

\n : newline

\t : horizontal tab

\\ : backslash

\" : double quote.

\000 : 1 to 3 digit octal value

Integer constants

Integer constants

An integer constant refers to a sequence of digits. It could be either positive or negative. and must have at least one digit.

It mustn't have a decimal point. No commas or blank are allowed within an integer constant. The allowable range for integer constants is -32767 to 32767.

There are three types of integer constants:

1. decimal :

In decimal notation ,simply we write decimal number. e.g. 24,678

2. octal :

In octal notation, write(0)immediately before the octal represention,e.g.-076,-076

3. hexadecimal :

In hexadecimal notation ,the constant is preceded by 0x,e.g.,0x3e,-0x3e.

Some example of integer constants:

: 426
: +762
: -8000
: -7605

Real constants

Real constants

Real constants are often called Floating Point constants.

It has three parts:

1. A sign (+ or -) preceding the number portion (optional).

2. A number portion (representing the base).

3. An exponent portion following the number portion (optional). This starts with E or E followed by an integer. The integer may be preceded by a sign.

A real constant must have at least one digit. It must have a decimal point. It could be either positive (default) or negative. No commas and blank are allowed within a real constant.

Some example of real constants:

: +.72
: +72
: +7.6E+2
: 24.4e-5

Logical & String constants

Logical & String constants

A logical constant can have either of two values either true or false. In C a non-zero value is always treated as true whereas zero is treated as false.

The logical constants are very useful in evaluating logical expressions and complex condition.

A group of character enclosed within a pair of double inverted commas (" ") is treated as a string constant.

some example of string constant:

: "Hello"
"Welcome to eBiz"
"a"

Introduction (operators in c)

Introduction

An operator specifies an operation to be performed. C is rich in operator. Operators join the various variables and constants to from an expression.

Some operator requires one operand and some require more than one operands.

An operator is a symbol that tells the computer to perform certain mathematical or logical manipulation in data stored in variables.

C is extremely rich in operators It has as many as 45 different operators.

Arithmetic operators

Arithmetic operators

Arithmetic Operators are used to Arithmetical calculation.

There are five Arithmetic operators in C:

Operator Purpose
+ Addition
- Subtraction
* Multiplication
/ Division
% Remainder after integer division

Relational operators

Relational operators

Relational operators are used to compare two operands and to check whether they are equal, unequal, greater than and lesser than other.

There are 6 relational operators:

Operator Meaning
< Less than
> Greater than
<= Less than equal to
>= Greater than equal to
== Equal to
!= Not equal to


The value of the relational operator is either one or zero. If the relation is true, result is 1 otherwise it is 0.

Copyright

Copyright © 2008 C Tutorial, All rights are reserved