Monday, 24 November 2014

Statements In C

 Statements

 The statements of a C program control the flow of program execution.In C language several kinds of statements are available. They are

  1. if statement 
  2. switch statement
  3. goto statement
  4. for statement 
  5. while statement
  6. do-while statement
  7. break statement 
  8. continue statement 
  9. expression statement
  10. compound statement 
  11. return statement 
  12. null statement

if statements


If statement is a conditional branching statement. In conditional branching statement a condition is evaluated, if it is evaluate true a group of statement is executed. The simple format of an if statement is as follows:

if (expression) 
        statement;

 If the expression is evaluated and found to be true, the single statement following the "if" is executed. If false, the following statement is skipped. Here a compound statement composed of several statements bounded by braces can replace the single statement.

Here's an example program using simple if statement:

if else statement:


                    This feature permits the programmer to write a single comparison, and then execute one of the two statements depending upon whether the test expression is true or false. The general form of the if-else statement is

if(expression)
          statement1
else
          statement2

                    Here also expression in parentheses must evaluate to (a boolean) true or false. Typically you're testing something to see if it's true, and then running a code block(one or more statements) if it is true, and another block of code if it isn't. The statement1 or statement2 can be either simple or compound statement.

The following program demonstrates a legal if else statement:

      This brings up the other if-else construct, the  if, else if, else. This construct is useful where two or more alternatives are available for selection.

The syntax is
if(condition)
          statement 1;
else if (condition)
          statement 2;
          .....................
          .....................
else if(condition)
         statement n-1;
else
          statemens n ;

                The various conditions are evaluated one by one starting from top to bottom, on reaching a condition evaluating to true the statement group associated with it are executed and skip other statements. If none of expression is evaluate to true, then the statement or group of statement associated with the final else is executed.

The following program demonstrates a legal if-elseif-else statement:

  c switch statement

    Switch statements simulate the use of multiple if statement.The switch statement is probably the single most syntactically awkward and error-prone feature of the C language. Syntax of c switch statement is

switch(expression)
          {
          case constant1:
                       statements 1;
           break;
           case constant2:
                       statements 2;
           break;
           …………………..
          default:
                       statements n;
           break;
          }

                  When the switch statement is executed, the expression in the switch statement is evaluated and the control is transferred directly to the group of statements whose case label value matches the value of the expression. Each group of statement ends with a break statement. The execution of break statement causes immediate exit from the switch statement. If break statement is not present, then the execution will falls trough all the statement in the selected case.  If none of the case-label value matches the value of expression, then none of the group within the switch statement will be selected and the control is transferred directly to the statement that follows the switch statement c.

                  The expression that forms the argument of switch is evaluated to either char or integer. Similarly the constant expression follows the keyword case should be a value int or char. That is, names of variable can also be used. Switch can test for only equality.

                   Take a look at the following if-else code, and notice how confusing it can be to have nested if tests, even just a few levels deep:

int number = 10;
if(number == 1)
         {
         printf("Given number is 1\n");
         }
else if((number == 2)
        {
        printf("Given number is 2\n");
        }
else if((number ==3)
        {
        printf("Given number is 3\n");
        }
else if((number ==4)
        {
        printf("Given number is 4\n");
        }
else if((number ==5)
       {
        printf("Given number is 5\n");
        }
else
        {
        if(number<0)
                   printf("Given number is negative\n");
        else
                   printf("Given number is greater than 5\n");
         }
Now let's see the same functionality represented in a switch construct:
                 It’s illegal to have more than one case label using the same value. For example, the following block of code won't compile because it uses two cases with the same.
int temp = 100;
switch(temp)
         {
         case 10 : printf("10");
         break;
         case 10 : printf("10"); // won't compile!
         break;
         case 100 :printf("1000");
         break;
         default : printf("default");
         break;
         }
Break and Fall-Through in switch Blocks:
                 When case constants are evaluated from the top to down, and the first case constant that matches the switch's expression is the execution entry point. In other words, once a case constant is matched, C will execute the associated code block, and all subsequent code blocks .
Example:















































Keywords ,Variables , Expression in C

Keywords

 Keywords are standard identifiers that have standard predefined meaning in C. Keywords are all lowercase, since uppercase and lowercase characters are not equivalent it's possible to utilize an uppercase keyword as an identifier but it's not a good programming practice.

Points to remember

1. Keywords can be used only for their intended purpose.

2. Keywords can't be used as programmer defined identifier.

3. The keywords can't be used as names for variables.

The standard keywords are given below:

The standard keywords are given below:








Variables

 Variables are means for location in memory used by a program to store data. The size of that block depends upon the range over which the variable is allowed to vary.
For example, on personal computer the size of an integer variable is two bytes, and that of a long integer is four bytes.
A variable region is temporarily remember a number or string value, such as covered by the program. To identify the variables, you have a name unique to every single variable. This is called a variable name. Before using a variable, use variables to what is called a variable declaration that you have to reveal the names and data types that can be stored in the variable variable.

The format for declaring a variable in C.
[Storage-class] type data variable name [= initial value];

Storage class and the initial value can be omitted.

The same data type and storage class variable can be declared, separated by commas.
[Storage-class] type data variable name [= initial value] variable [= initial value] variable [= initial value];
              In C the size of a variable type such as an integer need not be the same on all types of machines. When we declare a variable we inform the compiler of two things, the name of the variable and the type of the variable. For example, we declare a variable of type character with the name i by writing:
char i;
             On seeing the "char" part of this statement the compiler sets aside one bytes of memory to hold the value of the character. It also sets up a symbol table. In that table it adds the symbol i and the relative address in memory where those one byte was set aside. Thus, later if we write: i = 'x'; we expect that,at run time when this statement is executed, the value 'x' will be placed in that memory location reserved for the storage of the value of i.
Following are the rules for naming the variables:
  1. All variables must be declared before they can appear in executable statement.
  2.  A declaration consists of a data type followed by one or more variable names separated by commas.
     Example: int a,b,c;
  3. Variables can be distributed among declarations in any fashion. The above declaration can be written as
    int a;
    int b,c;
  4. Integer type variables can be declared to be short integer for smaller integer quantities or long integer for larger integer quantities.
    Example:
    short int a,b,c;
    long int a,b,c;
  5. An integer variable can also be declared to be un signed by writing unsigned int.
    Example: unsigned int;
Example:

Expressions

              An expression is a sequence of operators and operands that specifies computation of a value. An expression may consist of single entity or some combination of such entities interconnected by one or more operators. All expression represents a logical connection that's either true or false. Thus logical type expression actually represents numerical quantities.
              In C every expression evaluates to a value i.e., every expression results in some value of a certain type that can be assigned to a variable. Some examples of expressions are shown in the table given below.
A+b
3.14*r*r
a*a+2*a*b+b*b
Example:














Thursday, 26 April 2012


Mouseover Hyperlinks Tips


If you want to make your site fancy, these tips are for you!
The tips and tricks in this post allow two different types of mouseover links.

The first is one that will act as if visitors have clicked the link when they have simply put their mouse on top of it.
For example, look at the following link:
Look at this site!
It was made with this code:
<a href=" "onmouseover="parent.location='http://google.com'"> Look
at this site!
</a>

Copy and paste the code into your HTML code and the change the text in italics and you are done!

The second mouseover link tip is one that will show a pop-up window when a visitor puts his or her mouse on the link.
Look at this link:
I like web pages
It was made with slightly different code than the previous tip. Look at the HTML:
<a href="" onMouseover="alert('That answer is correct')">I like web pages</a>
Copy and paste that code into your web page's HTML code and remember to change the text in italics.

The Nice Mailto Trick


If you ever want someone to e-mail you, than mailto is your answer!
When you insert this command into your html code, a link will be created.
Whoever clicks on this link will have their default mail client pop up!
Look at this code:
<A HREF="mailto:?">Send me an email</A>
This is how it looks to the viewer:
Send me an email
We can also before the question mark, type in the address which the viewer is to send the e-mail to, and look at what happens.
<A HREF="mailto:Vishrulzz@ymail.com?">Send me an email</A>
Send me an e-mail
We can also add something to the subject line, too.
Look at what happens. We have added subject=This text is on the subject line&
<A HREF="mailto:
Vishrulzz@ymail.com?subject=This text is on the subject line&">Send me an email</A>
Send me an e-mail
OK, finally, we can even add text in the actual e-mail!
Look at what happens as we add body=This text is in the e-mail
<A HREF="mailto: Vishrulzz@ymail.com ?subject=This text is on the subject line&body=This text is in the e-mail">Send me an email</A>
Send me an e-mail 
Check It out...
Have fun..

Linking to Other Parts of the Same Webpage


Before you can link to a part of your webpage you need to mark that part of the web page.
You do this by inserting this into the webpage:
<A NAME="Anyname"> Bla, bla, bla </A>
This is how it looks to the viewer:
Bla, bla, bla
Then, you make the link. Here's the code:
<A HREF="#Anyname">Go back to  
 Bla, bla, bla  </A>
Here's the output: (See what happens)
Go back to bla, bla, bla
Oooh.

Having Columns Like in a Newspaper


This is column 1 and this is column 1 and this is still column 1This is column 2 and this is column 2 and this is still column 2This is column 3 and this is column 3 and this is still column 3

The source code for the colums was this:
<TABLE BORDER="0">
 <TR>
 <TD WIDTH="30%" VALIGN="TOP">
  This is column 1 and this is column 1 and this is still column 1<BR>
 </TD>
 <TD WIDTH="5%"></TD>
 <TD WIDTH="30%" VALIGN="TOP">
  This is column 2 and this is column 2 and this is still column 2<BR>
 </TD>
 <TD WIDTH="5%"></TD>
 <TD WIDTH="30%" VALIGN="TOP">
  This is column 3 and this is column 3 and this is still column 3<BR>
 </TD>
 </TR>
</TABLE>

 

When inserting the code, make sure you put it into very few lines.
Change all the little percentages to adjust the coloums, and also make sure you change the text. 

Have Text Highlighted


This is the code for normal text: 
HTML TEXT 
It will create this: 
HTML TEXT 
To have HTML highlighted, change the code to this: 
<span style="background-color: #FFFF00">HTML</span> TEXT 
It will create this: 
HTML TEXT 
This html tip will make your page even fancier.