Tuesday, April 26, 2016

Introducton to C-Programming

What is C?

'C' is a programming language developed at Bells lab of USA in 1972. It was designed and written by Dennis Ritchie. 'C' becomes too much popular because it is reliable, simple, portable and easy to use. It is not ties to anyone operating system or machine. It is also called System Programming Language because it is useful for writing compiler and operating system. It has been used to write major programs in many different domains.
The first major use of the 'C' was to write and operating system known as UNIX. UNIX is the most widely used operating system for all varieties of computers. The current popularity of 'C' due to its efficiency and its connection with UNIX. Many ready-made programs used by UNIX are written in C. 

Importance of C

1. It is simple and easy language with rich set of inbuilt functions.
2. Programs written in 'C' are efficient and fast.
3. It is highly portable.
4. Major parts of popular operating system like Windows, UNIX, and Linux etc. are written in 'C'.
5. It is also used to write programs for mobile or any other microprocessor based systems.
6. Provides easier way to handle hardware devices. 

Variable

In 'C', a quantity that may change during program executions called variable. A variable may take different value at different time during the execution of program. Variable names are names given to locations in the memory of computer, where different constants are stored. These locations can contain integer, real or character constant.
A variable name can be given by Programmer in a meaningful way so as to reflect its functions per nature in the program. The syntax of variable deceleration is
Data type                variable 1, variable2 …
Example: int x,y,Average,Sum; 

Rules for Constructing Variable names:

1. A variable name is any combinations of alphabetical, digits or underscore.
2. The first character in the variable name must be an alphabet or underscore.
3. No commas or blank spaces are allowed within a variable name.
4. No special symbol other than underscore can be used in a variable name.
5. A keyboard cannot be used as a variable name.
6. Uppercase and Lowercase letter are different.
7. Length of variable names are compiler dependencies. 

Constant 

A quantity that does not change during the execution of a program is known as constant. Example: 100, 17.5, 'A', '5', etc. 

Types of Constant

1. Primary Constant

a. Integer Constant

b. Floating Constant

c. Character Constant  

2. Secondary Constant

a. Array 

b. Structure

c. Union, etc.  

 

1. Primary Constant  

 

a. Integer Constant:

An integer constant is a sequence of digits without decimal point. Example: 100, 75, 99,etc. 

Rule for constructing integer constant:

-->An integer constant must have at least one digit.
-->It must not have a decimal point.
-->It can be either positive or negative but default sign is positive.
-->No commas or blank spaces are allowed within an integer constant.
-->The range of value for integer constant is -32768 to 32767. 

b. Floating (real) Constant: 

Numeric constant that contain decimal point are called real constant or floating point constant. Example: 175.00, 99.05, etc. 

Rules for constructing real/floating point constant:

--> A real constant must have at least one digit.
--> It must have decimal point.
--> It could be either positive or negative but the default sign is positive.
--> No commas or blank spaces are allowed within a real constant.
--> The range of value for real constant is -3.4e38 to 3.4e38. 

c. Character Constant:

A constant that contains a single alphabet or a single digits enclosed within single inverted commas is called a character constant. Example: 'A' , '5', '+', '=', etc. 

 

Rule for constructing character constant:

--> A character constant must be single alphabet, a single digit or a single special symbol enclosed within single inverted commas.
--> Both the inverted commas should pint to the left.
--> Maximum length of a character constant can be one character.

2 comments:

Popular Posts