Friday, 21 February 2014

SEE, 'C' is SEA



Hai friends:
            C, Sea, See -1 welcomes you all. In this series of episode, I’m going to post the basics of C language. As against the post title C is not so big. It’s actually confined even lacking the most basic input and output operation. But on the other hand, C is really sea that it can be widened to include library and user defined functions. Even though CPP and Java are sitting in the driving seat, C still holds the grip and reserves its own space. Why? Why C is so important?
1.     Nobody can learn CPP or Java directly. They have to thorough with C before migrating to those languages.
2.     Major parts of popular Operating Systems are still written in C.
3.     Many mobile devices where speed has to be achieved with limited amount of memory use C.
4.     Arcade games are known for their speeds. This is where C scores more than other languages.
5.     C provides feasible ways to interact with the hardware devices.

Before getting wet into C deeper, we have to be clear with C elements and some zeroth level works. So what are we waiting for? Let’s dive in…
C character set:
C Character Set is exactly the same as alphabets in English. Like the English language is developed using alphabets, C is built using the Character set. The Character set includes constants, variables and keywords.


A,B,C,……Z
a,b,c,……z
0,1,2,3,…9
. , ‘ “ ; : > < ? } { ( ) - + = _ ! & * / | etc.,
C character Set


Constants:
            Constants are those whose values can’t be changed. There are two types of constants in C. They are primary and secondary constants. Primary constants include integer, float and character while secondary includes array, pointer, structure, union... Now consider this. Computer memory is made of smaller cells as seen below. Each cell has its own address. Now for a value to be stored in the memory it must be stored in any of these cells.















3



































Here a value 3 is stored in one of the cells. The value of 3 is going to be 3 all the time, so it is what a constant is. If we want to use this value in our program, we have to call this memory location which could be tedious. Can’t it be nice to use names to call these values? Yes, we can! These names are called variables. The value of the variables can change which is self-explanatory. Now let’s choose a variable, say x. Now the statement x=3 leads to the value 3 stored in the variable x. It is to be noted that each variable can contain only one data at a time. So if we hen declare x=5, it will replace the previous value 3 and now x will contain 5.
We have seen that there are 3 types of constants under the primary type. Let’s discuss each in brief. Secondary types are reserved for future posts.
Integer Constants:
1.     Integer constants are nothing but the whole numbers but include both +ve and –ve numbers.
2.     No commas or blank spaces to be inserted while declaring it.
3.     It must not have any decimal point.
4.     The range of integers depends on compilers. For a 16-bit compiler the range is -32768 to 32767. (range sense the upper and lower boundary values that an integer can take).
e.g: -320, 6000, 32765 are all possible but not 32768 and more.

Floating point Constants:
1. Integer constants are nothing but the whole numbers but include both +ve and –ve numbers.
2. No commas or blank spaces to be inserted while declaring it.
3.     It must contain decimal point.
4.     It can be expressed as exponential form also. While expressing as exponential, e should be included to separate mantissa and exponential part.
5.     The range of floating point is -3.4e38 to 3.4e38.

E.g: 56.87, 3.14, 50e-3, 3e8.
Character Constants:
1.     A character should be enclosed by a single quote.
2.     Each variable can contain only one character at a time.
E.g: ‘A’, ‘a’.

Variables: If there are three types of primary constants, the variables holding them must also be three types. Yes, indeed. Each variable can contain data of same type only and does not permit heterogeneous data. For instance, if a variable x contains integer data type then it can’t hold data types other than integer.
Unlike Constants, there exists same set of rules for declaring all types of variables. They are as follows:
1.     The maximum allowable range for variable name is 31 (some compilers can have extended range).
2.     Each variable must starts with alphabetic or underscore.
3.     Numbers can be included in the middle or at the end of the variable.
4.     No special character should be used other than underscore in a variable.
Now a question arises? If all the data types are declared using same set of rules how the compiler distinguishes between them. The answer is flat. We have to declare which data type it belongs to using keyword.
E.g: int a;
float b;
char c;
here int, float and char refers to keywords.
Keywords:
 Keywords are reserved words in C language that have special functions. In other words, the meanings of keywords are already told to the compiler. There are 32 keywords in C. These keywords can’t be used as variables. The list of keywords is as follows. I prefer to define them when their use comes rather now.


auto               double           int                   struct
break             else                 long                switch
case                enum             register         typedef
char                extern            return            union
const              float               short              unsigned
continue       for                  signed            void
default           goto               sizeof             volatile
do                   if                      static              while

and now we are one step away from writing C program. Let’s define few points that are to be considered while writing C program.
1.     C program is a free form program that it has no specific rules on the starting point of the statement.
2.     C program is sequential that it should be written in the order of its execution.
3.     Every statement must be terminated by a semicolon (;).
4.     Blank spaces may be introduced between the words to increase the readability of the program.
That’s all for now. Let’s start our first C program in the very next post.

No comments:

Post a Comment