Loading....
Coupon Accepted Successfully!

 

Syntax

if (expression)

statement;

or

if (expression)

{

Block of statements;

}

if condition is true ? then X return value : otherwise Y value;


switch statement:

The switch statement is much like a nested if .. else statement. Its mostly a matter of preference which you use, switch statement can be slightly more efficient and easier to read.

Syntax:

switch( expression )

{

case constant-expression1: statements1;

[case constant-expression2: statements2;]

[case constant-expression3: statements3;]

[default : statements4;]

}


Using break keyword:

If a condition is met in switch case then execution continues on into the next case clause also if it is not explicitly specified that the execution should exit the switch statement. This is achieved by using break keyword.

 

Looping

Loops provide a way to repeat commands and control how many times they are repeated.


while loop

A while statement is like a repeating if statement. Like an If statement, if the test condition is true: the statments get executed. The difference is that after the statements have been executed, the test condition is checked again. If it is still true the statements get executed again.This cycle repeats until the test condition evaluates to false.


syntax of while loop

while ( expression )

{

Single statement

or

Block of statements;

}

 

for loop

for loop is similar to while, it’s just written differently. for statements are often used to proccess lists such a range of numbers:


Syntax of for loop

for( expression1; expression2; expression3)

{

Single statement

or

Block of statements;

}


do...while loop

do ... while is just like a while loop except that the test condition is checked at the end of the loop rather than the start. This has the effect that the content of the loop are always executed at least once.

syntax of do...while loop

Do

{

Single statement

or

Block of statements;

}while(expression);


Control Statement Description

break statement Terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch.

continue statement Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.

goto statement Transfers control to the labeled statement. Though it is not advised to use goto statement in your program.

printf() function

This is one of the most frequently used functions in C for output.

scanf() function

This is the function which can be used to to read an input from the command line.


C - Pointing to Data

A pointer is a special kind of variable. Pointers are designed for storing memory address i.e. the address of another variable. Declaring a pointer is the same as declaring a normal variable except you stick an asterisk ‘*’ in front of the variables identifier.

  • There are two new operators you will need to know to work with pointers. The “address of” operator ‘&’ and the “dereferencing” operator ‘*’. Both are prefix unary operators.
  • When you place an ampersand in front of a variable you will get it’s address, this can be stored in a pointer variable.
  • When you place an asterisk in front of a pointer you will get the value at the memory address pointed to.





Test Your Skills Now!
Take a Quiz now
Reviewer Name