User:Madhunalla/sandbox

Introduction to c language: What is C C language is a general purpose and structured pragramming langauge. It is also called as 'Procedure oriented programming language. C is not specially designed for specific applications areas like COBOL (Common Business-Oriented Language) or FORTRAN (Formula Translation). It is well suited for business and scientific applications. It has some various features like control structures, looping statements, arrays, macros required for these applications. The C language has following numerous features as: •	Portability •	Flexibility •	Effectiveness and efficiency •	Reliability •	Interactivity Who discovered C C is a programming language developed at AT & T’s Bell Laboratories of USA in 1972. It was designed and written by a man named Dennis Ritchie. The programming language C was designed to run on a PDP-11 with a UNIX operating system. Although it was originally intended to run under UNIX, there has been a great interest in running it under the MS-DOS operating system on the IBM PC and compatibles. It is an excellent language for this environment because of the simplicity of expression, the compactness of the code, and the wide range of applicability. Also, due to the simplicity and ease of writing a C compiler, it is usually the first high level language available on any new computer, including microcomputers, minicomputers, and mainframes. Tokens in C

C has different types of tokens. Tokens are the smallest different and individual independent units used in C program. When the C compiler is processing the source code of a C program, each group of characters separated by white spaces is called Tokens.

The different types of tokens used in C are: •	Keywords •	Identifiers •	Constants •	Variables •	Operators •	Strings •	Other Separators Keywords: •	Keywords are the reserve words which can not be used as variables. •	These are the system defined variables. •	C++ has many different keywords. •	White spaces are not allowed in keywords. •	These are in lower case. Following table shows the common keywords present in both C and C++. int	float	double	long short	signed	unsigned	const if	else	switch	break default	do	while	for register	extern	static	struct typedef	enum	return	sizeof goto	union	auto	case void	char	continue	volatile

Identifiers: •	These are the words or names which identify whether it is a constant, variable or function name in C. •	It represents unique sequence of characters. •	These must be maximum upto 31 characters long. •	All the identifiers are case sensitive. •	Special characters or keywords should not be used as identifiers. Rules in C for creating identifiers are: •	Only alphabet characters, digits and underscores are permitted. •	The name can't be started with digit. •	The keyword can't be used as a name. •	These are case sensitive. •	Identifier name can't have space. •	The name can't have a special character. Example:

Following are some valid identifiers:

number, number1, x, xyz etc.

Following are the Invalid identifiers:

7xy(first letter is digit), first name(has space), break(reserve word) Variables •	A variable is a place to store a piece of information. •	Variables are those quantities whose value vary during the execution of the program. •	Variable name is a name given to memory cells location of a computer where data is stored.

Declaring a Variable:

You have to tell the computer that you are going to store a number in a variable before you can actually do it. This is called variable declaring. To declare a variable, you need to know what kind of information it will store like will it store an integer number, floating number or a text-string, or something else.

This will be done by using 'DATA TYPES'.

Syntax:

Data type variable-name

Example :

int x, float y

Rules of naming variables : •	Variable name must begin with a letter. •	Keywords are not allowed to use as a variable name. •	White space is not allowed. •	Only underscore, special symbol is allowed between two characters. •	Variable names are case sensitive, hence x and X are different. •	These can't have special characters. •	The length of indentifier may be upto 31 characters but only only the first 8 characters are significant by compiler.

Constants:

Constants are those quantities whose value does not vary during the execution of the program that is, value is fixed.

C has two types of constants :

1. Numeric constants 2. Non numeric constant

Numeric constants :

Thses have numeric value having combination of sequence of digits i.e. from 0-9 as alone digit or combination of 0-9 with or without decimal point having positive or negative sign.

These are further sub-divided into two categories :

(a) Integer Numeric constant (b) Real or float Numeric constant

Integer Numeric constant : •	These have integer data combination of 0-9 without any decimal point. •	It can be positive or negative. •	Use of blank space and comma is not allowed between integer constants. •	Example:

420,-34 etc.

Real or Float Numeric constant : •	It must have at least one digit. •	It must have a decimal point which may be positive or negative. •	Use of blank space and comma is not allowed between real constants. •	Example:

20.4,52.54 etc. Character constants :

These have either a single character or a group of characters or a character with backslash used for special pupose.

These are of following types :

1. Single character constant 2. String character constant 3. Backslash character constant

Single character constant : •	It is a single alphabet or a digit or a special symbol enclosed in a single quote. •	Maximum length of a character constant is 1. •	Example:

'A','R','$' etc.

String character constant : •	It is collection of characters enclosed in double quotes. •	It may contain letters, digits, special characters and blank space. •	Example:

"bestprogrammingtutorials"

Escape Sequence Characters (Backslash Character Constants) in C:

C supports some special escape sequence characters that are used to do special tasks.

These are also called as 'Backslash characters'.

Some of the escape sequence characters are as follow:

Character- Constant Meaning

\n- New line (Line break) \b- Backspace \t - Horizontal Tab \f --Form feed \a - Alert (alerts a bell) \r - Carriage Return \v - Vertical Tab \? - Question Mark \' -- Single Quote \'' -- Double Quote \\ --Backslash \0--Null

Comments

There are two types of comments

1. // (Single Line Comment)

Any line that starts with a // is a comment

eg : clrscr; // to clear the screen

2. /* (Multiple Line Comment)



Example :

/*

Program To Display

Welcome Message On The Screen



Comments Statements are not executable statements.

Comments are used for user help.

Structure of C Program Document Section Links Section (File) Definition Section Global variable declaration Section void main {   Variable declaration section Function declaration section executable statements; } Function definition 1 - - Function definition n Document Section : It consists of set of comment lines which include name of a program, author name, creation date and other information. Links Section (File) : It is used to link the required system libraries or header files to excute a program. Definition Section : It is used to define or set values to variables. Global variable declaration Section : It is used to declare global or public variable. void main : Used to start of actual C program. It includes two parts as declaration part and executable part. Variable declaration section : Used to declare private variable. Function declaration section : Used to declare functions of program from which we get required output. Then, executable statements are placed for execution. Function definition section : Used to define functions which are to be called from main.