RSS

Get Started With C – Basics

17 May

->C is a STRUCTURED , HIGH LEVEL and MACHINE INDEPENDENT programming language.

-> STRUCTURED programming technique supports the following 3 Concepts :-

1.Sequence

This programming language supports stepwise execution of statements.

2.Selection

C language can check a particular condition. It has 2 outputs either TRUE or FALSE. 

3.Iteration

As the name says, it repeats the execution of some particular statements a given number of times.

A Small history…

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. In the late seventies C began to replace the more familiar languages of that time like PL/I, ALGOL, etc. Thus, without any advertisement C’s reputation spread and its pool of users grew.

Possibly why C seems so popular is because it is reliable, simple and easy to use. Moreover, in an industry where newer languages, tools and technologies emerge and vanish day in and day out, a language that has survived for more than 3 decades has to be really good.

STEPS TO LEARN C:-

C  CHARACTER SET:-

It can be alphabet, digit or special symbol used to represent information.

Constants, Variables and Keywords:-

->The alphabets, numbers and special symbols when properly combined form constants, variables and keywords. Let us see what are ‘constants’ and ‘variables’ in C. A constant is an entity that doesn’t change whereas a variable is an entity that may change.

->Here 3 is stored in a memory location and a name x is given to it. Then we are assigning a new value 5 to the same memory location x. This would overwrite the earlier value 3, since a memory location can hold only one value at a time.

->Since the location whose name is x can hold different values at different times x is known as a variable. As against this, 3 or 5 do not change, hence are known as constants.

Types of C Constants:-

C constants can be divided into two major categories:

  1. Primary Constants
  2. Secondary Constants

Rules for Constructing Integer Constants:-

  1. It must not have a decimal point.
  2. It can be either positive or negative.
  3. If no sign precedes an integer constant it is assumed to be positive.
  4. No commas or blanks are allowed within an integer constant.
  5. The allowable range for integer constants is -32768 to 32767.

Truly speaking the range of an Integer constant depends upon the compiler. For a 16-bit compiler like Turbo C or Turbo C++ the range is –32768 to 32767. For a 32-bit compiler the range would be even greater.

Examples:-  125 , +7000 , -600 , -7005

Rules for Constructing Real Constants(Floating Point constants)

A real constant must have at least one digit.

  1. It must have a decimal point.
  2. It could be either positive or negative.
  3. Default sign is positive.
  4. No commas or blanks are allowed within a real constant

Examples:- +325.34 , 426.0 , -32.76 , -48.5792

Rules for Constructing Character Constants:-

  1. A variable name is any combination of 1 to 31 alphabets, digits or underscores. Some compilers allow variable names whose length could be up to 247 characters. Still, it would be safer to stick to the rule of 31 characters. Do not create unnecessarily long variable names as it adds to your typing effort.
  2. The first character in the variable name must be an alphabet or underscore.
  3. No commas or blanks are allowed within a variable name.
  4. No special symbol other than an underscore (as in gross_sal) can be used in a variable name.

Examples:-  si_int  , m_hra , pop_e_89

C compiler is able to distinguish between the variable names by making it compulsory for you to declare the type of any variable name that you wish to use in a program. This type declaration is done at the beginning of the program. Following are the examples of type declaration statements:

Examples:-  int si, m_hra ;

float bassal ;

char code ;

Thus, if we want to calculate simple interest, it is always advisable to construct meaningful variable names like prin, roi, noy to represent Principle, Rate of interest and Number of years rather than using the variables a, b, c.

C Keywords:-

Keywords are the words whose meaning has already been explained to the C compiler. The keywords cannot be used as variable names because if we do so we are trying to assign a new meaning to the keyword, which is not allowed by the computer. The keywords are also called ‘Reserved words’. There are only 32 keywords available in C.


 

Leave a comment