Tuesday, 4 October 2011

What If ..... then Else....

Its been such a looong time isn't it ?
well .. I was busy .. engrossed in my work so much that I did not get time to study C ..... sorry for that . So lets start studying now.

The topic which we will touch is Decision Making which plays very important part in development of programs which we will soon learn. so tuck in .

While developing or creating an application or program we may not need to execute the situations sequentially. Decision making help us in determining the flow of the execution of the program. a decision control instruction or decision making can be implemented in C using:
(a) The if statement
(b) The if-else statement
(c) The conditional operators


For the time being lets look at the If statement.....

The If Statement

The syntax of if statement looks like this:


if ( this condition is true )
execute this statement ;

whenever if block comes it tells compiler that what comes after it is a decision control statement. If the condition is true then and only then execute the the statement otherwise move ahead and skip the if block.

The entries or statements within the two curly braces( { , } )are called as block

But do you know what the important thing I have missed ????
..
..
..
..
..
..

How will we know whether the condition is true or not ??
The answer is ..... wait for it ...... Relational operators in C
Here's One diagram for you to learn the Relational Operators...



but even though you are able to understand the diagram then you will not get feel of it unless you see and example .. right people ???
Here 1 ... cherry on top ....




Example :

void main()
{
int price;

printf(" Enter price of the ice-cream : ");
scanf("%d",&price);

if( price > 20 )
{
printf("Let me Give you a Huge Cherry on TOP :) ");
}
}

on execution of this program if you enter price more than 20 then the if condition will execute and the statement will be printed on console.

Still not able to understand ?? .............. ok .... then for those who are still getting confused , I have one more li'l thing to share ... FLOW CHART ^^
Here's one of above example.....




Guess............. that should be enough for today .... but let me give you a very interesting exercise.

Can you write a program from a flow chart ??? ....... can you ?? ..just try it.

Here's a Flow chart


So long folks .......... Lets meet again and study :) .... ciao

Tuesday, 3 May 2011

Let US C !!!!



" C "
    Brian Kernighan and Dennis Ritchie never even thought that their daughter would revolutionize the entire world. They just tried to give birth to a simple and multitasking beauty which will help them to carry out their desired task in their operating system "Unix" .
But " C" charmed tech people in such a way that not only they fell for her but also got addicted to her a lot.
    The  reason "C" became so popular because its simple , reliable and easy to use as well as understand. Many will think that "C" is soooooo outdate so why should i bother learning "C" ? , instead i will go with "Java" or  "Dot Net" !!! . But what i think differs from it a lot and soon you will know why I think like that.

1) Nobody can learn "Java / Dot Net " without learning "C". Because those languages contains many essential but mighty powerful things like "Classes " , "Inheritance" , "Polymorphism" , "Encapsulation / Abstraction " etc ..........  So learning these things without getting thorough with the simple basic concepts is like " putting Cart before Horse ". So one should start from charming gal  that is  "C" and move ahead to matured ladies. ;D

2)Many people may not know this but most of the part of the popular Operating Systems like " Windows " ," Unix " are still made from "C" , since the execution speed or the speed at which "C" carries out the tasks is unbeatable not even by "Java" or "Dot Net".

3)Also devices which have become part of our life that is Cellphones , Palmtops or even food processor , Oven ( you can add washing machine in this list tooo  :P ) are working on the small microprocessor i.e. an OS and program embedded in small chip are working due to "C".

4)One more thing of Great Interest is "GAMES" . The objects navigated by user for example .. a bot or a spaceship ..... what if it takes tooooooo long to move ???? ..........you will get bored right ?? .. these things are also Created ( written ) using "C" programming.

Thats why IT people who were loving womens like  "Pascal" , "Fortran" , ended up marrying to "C".(Just Like me :P ^^)

So Lets start learning more about "C". Shall we ??


Getting to Know the Supergal " C " :-

If you know English Language you can easily learn " C ". because There is close analogy between learning English and Learning " C ". In english we learn "Alphabets then words and then Sentences" . The same thing happens in " C ". You can get an idea of it from the diagram below......






So let move ahead .........


C : The Character Set

A diagramatic representation is always better ... dont you think ??? .... here you go !!!!!!


These are the characters which are allowed for extensive use in "C" .

Constant , Variables and very important "Keywords"

"Constant" as its meaning suggests is a Constant or we can call it never changing ............opposite of "Variable" .
Constant is an entity that never changes where as variable is an entity that may change. Just like human memory , memory of computer is made up of millions of small parts , lets call them memory cells !!
These memory cells can hold many values. If the values stored at one memory cell cannot be changed then that value is constant and if it can be overwritten then that value is variable.

Type Of  " C " Constants :

C constants are divided into 2 major categories :
1) Primary Constant
2) Secondary Constant

Lets see the diagram again ......


Since we are at a beginners level ............ lets stay beginner for the time being ........we will study only the Integer , real , Character Constant for now.

Rules for Integer Constants
(a) An integer constant must have at least one digit.
(b) It must not have a decimal point.
(c) It can be either positive or negative.
(d) If no sign precedes an integer constant it is assumed to be positive.
(e) No commas or blanks are allowed within an integer constant.
(f) The allowable range for integer constants is -32768 to 32767. ( Actually the range for the integer is         dependent on the compiler. For 32 bit compiler , integer has even higher range. To know about compiler
please click   what compilers ??? )

Ex. 123 , 321 , +768 , +911111 etc


Rules for Constructing Real Constants

Real constants are often called Floating Point constants. The real constants could be written in two forms—Fractional form and Exponential form.

Following rules must be observed while constructing real constants expressed in fractional form:
(a) A real constant must have at least one digit.
(b) It must have a decimal point.
(c) It could be either positive or negative.
(d) Default sign is positive.
(e) No commas or blanks are allowed within a real constant.


ex. 123.43 , +2434.33 , -12222.22 , -45823. 034 etc.

We can also use Exponential Constants. These are only used if the value is very very small or very very large.
They are not different from the Real Constants but very useful.
In exponential form of representation, the real constant is represented in two parts. The part appearing before ‘e’ is called mantissa, whereas the part following ‘e’ is called exponent.
Following rules must be observed while constructing real constants expressed in exponential form:
(a) The mantissa part and the exponential part should be separated by a letter e.
(b) The mantissa part may have a positive or negative sign.
(c) Default sign of mantissa part is positive.
(d) The exponent must have at least one digit, which must be a positive or negative integer. Default sign is    positive.
(e) Range of real constants expressed in exponential form is -3.4e38 to 3.4e38.

Ex.:  +3.2e-5 , 4.1e8 ,-0.2e+3,-3.2e-5 etc.

and Last one but also equally important ......

Rules for Constructing Character Constants
(a) A character constant is a single alphabet, a single digit or a single special symbol enclosed within single inverted commas. Both the inverted commas should point to the left. For example, ’A’ is a valid character constant whereas ‘A’ is not.
(b) The maximum length of a character constant can be 1 character.
Ex.: 'A' , 'I','5','=' etc


This is for now folks .............. we will see "Variables" next time ........... now after such a hard , brainracking reading there should be li'l fun right ???  ..... so here you go ...........


I will be waiting for your comments , suggestions and Questions....