Study Anytime Any Where We Will Open The Knowledge For You Anish Sir 24x7 Learning solution It Is Time to join JOB
23 October 2017

Study Anytime Any Where

23 October 2017

We Will Open The Knowledge For You

23 October 2017

Anish Sir 24x7 Learning solution

23 October 2017

It Is Time to join JOB

C Programming

C++ Programming

JAVA Programming

Android Language

Android-logo.png

.Net Programming

net-logo-b55c217213ae49991589ed43d7ed58a7.png

c# Programming

photo_1389636992_quiz_image_temp.png

Asp .Net

asplogo-square.png

PHP Programming

58481791cef1014c0b5e4994.png

Search Your Topic

config
Anish Sir

Anish Sir

"I am delighted once again to pen the welcome note to the Tosh!Yas Technologies ."

 Call +91 74 88 34 7779  | Email : anishsingh@live.com

Website URL: http://toshiyas.in
Friday, 15 September 2017 08:54

C- if else Program

C-Program to Check Even or Odd

#include <stdio.h>
int main()
{
    int number;

    printf("Enter an integer: ");
    scanf("%d", &number);

    // True if the number is perfectly divisible by 2
    if(number % 2 == 0)
        printf("%d is even.", number);
    else
        printf("%d is odd.", number);

    return 0;
}


Output

Enter an integer: -7
-7 is odd.

C-Program to Check Odd or Even Using Conditional Operator

#include <stdio.h>
int main()
{
    int number;

    printf("Enter an integer: ");
    scanf("%d", &number);

    (number % 2 == 0) ? printf("%d is even.", number) : printf("%d is odd.", number);

    return 0;
}

 

Program to display a number if user enters negative number

// If user enters positive number, that number won't be displayed

#include <stdio.h>
int main()
{
    int number;

    printf("Enter an integer: ");
    scanf("%d", &number);

    // Test expression is true if number is less than 0
    if (number < 0)
    {
        printf("You entered %d.\n", number);
    }

    printf("The if statement is easy.");

    return 0;
}

Output 1

Enter an integer: -2
You entered -2.
The if statement is easy.

When user enters -2, the test expression (number < 0) becomes true. Hence, You entered -2 is displayed on the screen.

Output 2

Enter an integer: 5
The if statement in C programming is easy.

Friday, 15 September 2017 07:42

C-Decision Statements

Decision making structures require that the programmer specifies one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.

Show below is the general form of a typical decision making structure found in most of the programming languages −

Decision making statements in C

C programming language assumes any non-zero and non-null values as true, and if it is either zero or null, then it is assumed as false value.

C programming language provides the following types of decision making statements.

Statement & Description

if statement

An if statement consists of a boolean expression followed by one or more statements.


Syntax

The syntax of an 'if' statement in C programming language is −

if(boolean_expression) {
   /* statement(s) will execute if the boolean expression is true */
}

If the Boolean expression evaluates to true, then the block of code inside the 'if' statement will be executed. If the Boolean expression evaluates to false, then the first set of code after the end of the 'if' statement (after the closing curly brace) will be executed.

C programming language assumes any non-zero and non-null values as true and if it is either zero or null, then it is assumed as false value.

Flow Diagram

C if statement
#include <stdio.h>
 
int main () {

   /* local variable definition */
   int a = 10;
 
   /* check the boolean condition using if statement */
	
   if( a < 20 ) {
      /* if condition is true then print the following */
      printf("a is less than 20\n" );
   }
   
   printf("value of a is : %d\n", a);
 
   return 0;
}

When the above code is compiled and executed, it produces the following result −
a is less than 20;
value of a is : 10

if...else statement

An if statement can be followed by an optional else statement, which executes when the Boolean expression is false.

An if statement can be followed by an optional else statement, which executes when the Boolean expression is false.

Syntax

The syntax of an if...else statement in C programming language is −

if(boolean_expression) {
   /* statement(s) will execute if the boolean expression is true */
}
else {
   /* statement(s) will execute if the boolean expression is false */
}

If the Boolean expression evaluates to true, then the if block will be executed, otherwise, the else block will be executed.

C programming language assumes any non-zero and non-null values as true, and if it is either zero or null, then it is assumed as false value.

Flow Diagram

C if...else statement

Example

#include <stdio.h>
 
int main () {

   /* local variable definition */
   int a = 100;
 
   /* check the boolean condition */
   if( a < 20 ) {
      /* if condition is true then print the following */
      printf("a is less than 20\n" );
   }
   else {
      /* if condition is false then print the following */
      printf("a is not less than 20\n" );
   }
   
   printf("value of a is : %d\n", a);
 
   return 0;
}

When the above code is compiled and executed, it produces the following result −

a is not less than 20;
value of a is : 100

If...else if...else Statement

An if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement.

When using if...else if..else statements, there are few points to keep in mind −

  • An if can have zero or one else's and it must come after any else if's.

  • An if can have zero to many else if's and they must come before the else.

  • Once an else if succeeds, none of the remaining else if's or else's will be tested.

Syntax

The syntax of an if...else if...else statement in C programming language is −

if(boolean_expression 1) {
   /* Executes when the boolean expression 1 is true */
}
else if( boolean_expression 2) {
   /* Executes when the boolean expression 2 is true */
}
else if( boolean_expression 3) {
   /* Executes when the boolean expression 3 is true */
}
else  {
   /* executes when the none of the above condition is true */
}

Example

#include <stdio.h>
 
int main () {

   /* local variable definition */
   int a = 100;
 
   /* check the boolean condition */
   if( a == 10 ) {
      /* if condition is true then print the following */
      printf("Value of a is 10\n" );
   }
   else if( a == 20 ) {
      /* if else if condition is true */
      printf("Value of a is 20\n" );
   }
   else if( a == 30 ) {
      /* if else if condition is true  */
      printf("Value of a is 30\n" );
   }
   else {
      /* if none of the conditions is true */
      printf("None of the values is matching\n" );
   }
   
   printf("Exact value of a is: %d\n", a );
 
   return 0;
}

When the above code is compiled and executed, it produces the following result −
None of the values is matching
Exact value of a is: 100
 

C - nested if statements

It is always legal in C programming to nest if-else statements, which means you can use one if or else if statement inside another if or else if statement(s).

Syntax

The syntax for a nested if statement is as follows −

if( boolean_expression 1) {

   /* Executes when the boolean expression 1 is true */
   if(boolean_expression 2) {
      /* Executes when the boolean expression 2 is true */
   }
}

You can nest else if...else in the similar way as you have nested ifstatements.

Example

#include <stdio.h>
 
int main () {

   /* local variable definition */
   int a = 100;
   int b = 200;
 
   /* check the boolean condition */
   if( a == 100 ) {
   
      /* if condition is true then check the following */
      if( b == 200 ) {
         /* if condition is true then print the following */
         printf("Value of a is 100 and b is 200\n" );
      }
   }
   
   printf("Exact value of a is : %d\n", a );
   printf("Exact value of b is : %d\n", b );
 
   return 0;
}
When the above code is compiled and executed, it produces the following result −
Value of a is 100 and b is 200
Exact value of a is : 100
Exact value of b is : 200

C - switch statement

 

switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case.

Syntax

The syntax for a switch statement in C programming language is as follows −

switch(expression) {

   case constant-expression  :
      statement(s);
      break; /* optional */
	
   case constant-expression  :
      statement(s);
      break; /* optional */
  
   /* you can have any number of case statements */
   default : /* Optional */
   statement(s);
}

The following rules apply to a switch statement −

  • The expression used in a switch statement must have an integral or enumerated type, or be of a class type in which the class has a single conversion function to an integral or enumerated type.

  • You can have any number of case statements within a switch. Each case is followed by the value to be compared to and a colon.

  • The constant-expression for a case must be the same data type as the variable in the switch, and it must be a constant or a literal.

  • When the variable being switched on is equal to a case, the statements following that case will execute until a break statement is reached.

  • When a break statement is reached, the switch terminates, and the flow of control jumps to the next line following the switch statement.

  • Not every case needs to contain a break. If no break appears, the flow of control will fall through to subsequent cases until a break is reached.

  • switch statement can have an optional default case, which must appear at the end of the switch. The default case can be used for performing a task when none of the cases is true. No break is needed in the default case.

Flow Diagram

switch statement in C

Example

#include <stdio.h>
 
int main () {

   /* local variable definition */
   char grade = 'B';

   switch(grade) {
      case 'A' :
         printf("Excellent!\n" );
         break;
      case 'B' :
      case 'C' :
         printf("Well done\n" );
         break;
      case 'D' :
         printf("You passed\n" );
         break;
      case 'F' :
         printf("Better try again\n" );
         break;
      default :
         printf("Invalid grade\n" );
   }
   
   printf("Your grade is  %c\n", grade );
 
   return 0;
}

When the above code is compiled and executed, it produces the following result −

Well done
Your grade is B
 
 

C - nested switch statements

It is possible to have a switch as a part of the statement sequence of an outer switch. Even if the case constants of the inner and outer switch contain common values, no conflicts will arise.

Syntax

The syntax for a nested switch statement is as follows −

switch(ch1) {

   case 'A': 
      printf("This A is part of outer switch" );
		
      switch(ch2) {
         case 'A':
            printf("This A is part of inner switch" );
            break;
         case 'B': /* case code */
      }
	  
      break;
   case 'B': /* case code */
}

Example

#include <stdio.h>
 
int main () {

   /* local variable definition */
   int a = 100;
   int b = 200;
 
   switch(a) {
   
      case 100: 
         printf("This is part of outer switch\n", a );
         switch(b) {
            case 200:
               printf("This is part of inner switch\n", a );
         }
   }
   
   printf("Exact value of a is : %d\n", a );
   printf("Exact value of b is : %d\n", b );
 
   return 0;
}

When the above code is compiled and executed, it produces the following result −
This is part of outer switch
This is part of inner switch
Exact value of a is : 100
Exact value of b is : 200
 
 
 
Thursday, 14 September 2017 10:16

Pre-Defined Groups

There are twenty eight pre-defined groups in Tally.ERP 9. These groups are a part of the chart of accounts for most organizations. For example, Sales Accounts is a pre-defined group. All sales ledgers can be classified under this group.

Out of the twenty eight pre-defined groups, fifteen are primary groups and thirteen are sub-groups. The user can create any number of primary groups and sub-groups.

Primary Groups
Subgroups
Branch / Divisions
 Bank Accounts
 Capital Account
 Bank OD A/c
 Current Assets
 Cash-in-hand
 Current Liabilities
 Deposits (Asset)
 Direct Expenses
 Duties & Taxes
 Direct Incomes
 Loans & Advances (Asset)
 Fixed Assets
 Provisions
 Indirect Expenses
 Reserves & Surplus
 Indirect Incomes
 Secured Loans
Investments
Stock-in-hand
Loans (Liability)
Sundry Creditors
Misc. Expenses (ASSET)
Sundry Debtors
Purchase Accounts
Purchase Accounts
Sales Accounts
Suspense A/c

Out of the fifteen primary groups, nine primary groups appear in the balance sheets that are capital in nature and six primary groups appear under Profit & Loss account which are revenue in nature.

The sub-groups that form a part of the balance sheet are:

Pre-defined Subgroups

Under

Bank Accounts

Current Assets

Bank OD A/c

Loans (Liability)

Cash-in-hand

Current Assets

Deposits (Asset)

Current Assets

Duties & Taxes

Current Liabilities

Loans & Advances (Asset)

Current Assets

Provisions

Current Liabilities

Reserves & Surplus

Capital Account

Secured Loans

Loans (Liability)

Stock-in-hand

Current Assets

Sundry Creditors

Current Liabilities

Sundry Debtors

Current Assets

Unsecured Loans

Loans (Liability)

Note: Primary groups cannot be deleted.

Thursday, 14 September 2017 06:32

Default Groups

In Tally.ERP 9, there are a number of default Groups that can be used for various accounts.

Capital Account

This records the Capital and Reserves of the company. The ledgers that belong to Capital Accounts are Share Capital, Partners' Capital A/c, Proprietor's Capital Account and so on.

Reserves and Surplus [Retained Earnings]

This contains ledgers like Capital Reserve, General Reserve, Reserve for Depreciation and so on.

Current Assets

Current Assets record the assets that do not belong either to Bank Accounts or to Cash-in-Hand sub-groups.

Bank Accounts: Current account, savings account, short term deposit accounts and so on.
 
 Cash-in hand: Tally.ERP 9 automatically creates Cash A/c in this group. You can open more than one cash account, if necessary.
Note: An account under Cash-in-hand group or Bank Accounts/Bank OCC A/c group is printed as a separate Cash Book in the traditional Cash Book format and does not form part of the Ledger.
 Deposits (Asset): Deposits contain Fixed Deposits, Security Deposits or any deposit made by the company (not received by the company, which is a liability).
 
Loans & Advances (Asset) This records all loans given by the company and advances of a non-trading nature (example: advance against salaries) or even for purchase of Fixed Assets. We do not recommend you to open Advances to Suppliers’ account under this Group. For further details, please refer to the section on Common Errors.
 
 Stock-in-hand: This group contains accounts like Raw Materials, Work-in-Progress and Finished Goods. The balance control depends on whether you have selected Integrated Account-cum-Inventory option while creating the company. (refer to Company creation section for more details) Let us consider these options:
 
Integrated Accounts-cum-Inventory: This option has a significant effect on the Balance Sheet and Profit & Loss Account. If set to Yes, it brings the stock/inventory balance figures from the inventory records and provides a drill down to the Stock registers from the Balance Sheet. You are not allowed to directly change the closing balance of an account under this group. You are allowed to pass transactions in Inventory records and the account balances are automatically reflected in the Balance Sheet as Closing Stock.
 

Non-integrated Accounts-cum-Inventory: If Integrated Account-cum-Inventory option is set to No, it ignores the inventory books figures and picks up manually entered closing stock balances from the ledger account created. This provides the facility to maintain accounts separately and inventory separately.

 

You are not allowed to pass transactions if your accounts that come under this Group. It allows you to hold opening and closing balances only. Since no vouchers can be passed for these accounts, they are the only accounts for which the closing balances can be directly altered (by an authorised user only).

 

Sundry Debtors: For customer accounts refer to common and possible errors in grouping of accounts section.

Current Liabilities

Accounts like Outstanding Liabilities, Statutory Liabilities and other minor liabilities can be created directly under this group. Sub-groups under Current Liabilities are Duties and Taxes, Provisions and Sundry Creditors

 Duties and Taxes: Duties and Taxes contain all tax accounts like VAT, CENVAT, Excise, Sales and other trade taxes and the total liability (or asset in case of advances paid) and the break-up of individual items.

 

 Provisions: Accounts like Provision for Taxation, Provision for Depreciation and so on are recorded under Provisions.

 

Sundry Creditors: For trade creditors, refer to common and possible errors in grouping of accounts section.

Investments

Group your investment accounts like Investment in Shares, Bonds, Govt. securities, long term Bank deposit accounts and so on. This allows you to view the total investments made by the company.

Loans (Liability)

Loans that a company has borrowed, typically long-terms loans.

 Bank OD Accounts [Bank OCC Accounts]:  Tally.ERP 9 provides you with distinct types of Bank Accounts,

 

Bank OCC A/c: To record the company's overdraft accounts with banks. For example, Bill Discounted A/c’s and Hypothecation A/c’s etc.

Note: An account under Bank OCC A/c group is printed as a separate Cash Book in the traditional Cash Book format and does not form part of the Ledger.

Secured Loans: Term loans or other long/medium term loans, which are obtained against security of some asset.   does not verify the existence of the security. Typical accounts are Debentures, Term Loans, and so on.

 

 Unsecured Loans: Loans obtained without any security. Example: Loans from Directors/partners or outside parties.

Suspense Account

In modern accounting, many large corporations use a Suspense Ledger to track the money paid or recovered, the nature of which is not yet known. The most common example is money paid for Traveling Advance whose details will be known only upon submission of the Travelling Allowance bill. Some companies may prefer to open such accounts under Suspense Account.

Loans and Advances (Asset) group: The Suspense Account is a Balance Sheet item. Any expense account even if it has 'suspense' in its name, it should be opened under Revenue group like Indirect Expenses and not under Suspense Account group.

Miscellaneous Expenses (Asset)

This group is typically used for legal disclosure requirements such as Schedule VI of the Indian Companies Act. It should hold incorporation and pre-operative expenses. Companies would write off a permissible portion of the account every year. A balance remains to an extent that cannot be written off in Profit & Loss Account. Tally.ERP 9 does not show loss, carried forward in the Profit & Loss Account, under this group. The Profit & Loss Account balance is displayed separately in the Balance Sheet.

Branch/Divisions

This maintains ledger accounts of all your company's branches, divisions, affiliates, sister concerns, subsidiaries and so on. Tally.ERP 9 permits Sales and Purchase transactions to take place with accounts opened here. Remember, these are their accounts in your books and not their books of accounts. Just treat them as any other party account. If you wish to maintain the books of a branch/division on your computer, you must open a separate company. (Tally.ERP 9 allows maintenance of multiple company accounts).

Sales Account

You can classify your sales accounts based on Tax slabs or type of sales. This also becomes a simple mechanism for preparation of Tax returns.

For example,

     Domestic Sales

     Export Sales

Now under Domestic Sales open the following ledgers:

     Sales (10%)

     Sales (5%)

     Sales (exempt)

You can even open an account as Sales Returns under the group Domestic Sales to view your net sales after returns (or the returns may be directly passed through Journal against the specific Sales account).

Note: Do not create customer accounts under this group. For more details, refer to common and possible errors in grouping of accounts section.

Purchase Account

This is similar to sales accounts, except for the type of transactions.

Direct Income [Income Direct]

These are Non-trade income accounts that affect Gross Profit. All trade income accounts fall under Sales Accounts. You may also use this group for accounts like Servicing, Contract Charges that follow sales of equipment.

For a professional services company, you may not use Sales Account group at all. Instead, open accounts like Professional Fees under this group.

Indirect Income [Income Indirect]

These are miscellaneous non-sale income accounts. Example: Rent Received and Interest Received.

Direct Expenses [Expenses Direct]

These are Manufacturing or direct trading expenses. These accounts determine the Gross Profit of the company.

Indirect Expenses [Expenses Indirect]

All administrative, selling or non-direct expenses.

Profit & Loss Account is a reserved primary account in Tally.ERP 9. You can use this account to pass adjustment entries through journal vouchers. For example, transfer of profit or loss account to Capital or Reserve account.

Common and Possible Errors in Grouping and Account Classification

Debtor/Creditor classification

Accounts of parties with whom your company is trading should be opened under any of the following groups (or sub-groups under them):

     Sundry Debtors

     Sundry Creditors

     Branch/Divisions

Sales and Purchase account groups are meant for revenue accounts and are reflected in the Profit & Loss Account. If you open party accounts under these groups, it becomes difficult to pass sales or purchase voucher transactions.

For example, in a sales voucher transaction entry, you must debit an account, which can be sundry debtor, branch/division or even a sundry creditor. Moreover, other facilities like bill-wise allocation and tracking will not be available unless the accounts belong to one of these groups.

Opening two accounts of the same party

Tally.ERP 9 classifies debtors, creditors and branch/divisions for convenience. This helps you in the process of keeping the accounts of a particular group together during display and analysis. Thus you can pass both sales and purchase entries for a party account placed under Sundry Debtors. Use the classification depending on the most natural group for the party.

For example, parties from whom you buy frequently can be placed under Sundry Creditors, as that is the natural place to look for their account. Tally.ERP 9 does not restrict the accounts from having obverse balances. Thus, a Sundry Debtor can have a credit balance depending on the state of his account.

Therefore, you need not open two accounts for the same party - one under Sundry Debtors and another under Sundry Creditors. Tally.ERP 9 restricts opening of two identical ledger accounts. In such cases, you may decide to circumvent by marking one account as "A & Co - S/Dr" and another "A & Co - S/Cr". This will allow you to have two accounts of the same party under two groups, but you will lose the advantage of analyzing net position at a single instance. It is always better to maintain a single account to obtain best benefits.

Expenditure items are entered under Liabilities group. For example, the expenditure item Rates & Taxes under the group Duties and Taxes.

The group Duties and Taxes is specifically meant to handle taxation liabilities of your company. Rates & Taxes and other statutory expenses should be placed under Indirect Expenses.

Simply adhering to the reserved groups may be sufficient for many organizations. For greater diversity, Tally.ERP 9 allows you to create your own groups, either as sub-groups or primary groups. Groups can be sub-classified to practically an unlimited level, giving you a virtual accounting tree. At the lowest level, of course, would be the ledger account.

Note: While it is necessary to assign every ledger to a group/sub-group, it is not essential to have your own sub-classification of accounts; you may simply use the reserved groups for grouping your ledger accounts.

Thursday, 14 September 2017 06:28

Groups

Groups are collection of ledgers of the same nature. Account groups are maintained to determine the hierarchy of Ledger Accounts, which is helpful in determining and presenting meaningful and compliant reports.  

Tally.ERP 9 has the flexibility of setting user required chart of accounts.  You can group the Ledger accounts under the required Groups at the time of creating the chart of accounts or you can alter them at any time.  

The Group behavior is classified into Capital or Revenue and more specifically into Assets, Liabilities, Income and Expenditure.  The Groups ascertain whether the same will affect Profit and Loss Account which is revenue in nature or Balance Sheet which is capital in nature.

Thursday, 14 September 2017 06:09

Accounts Information

The accounts information lists accounting masters like groups, ledgers and voucher types with which you can provide company's account details.

Accounts information provides:

     Single master option to work with one master at a time.

     Multiple masters option to work with many sub-masters at a time. A sub-master behaves exactly like a master. 

To access the accounts information

1.    Go to Gateway of Tally > Accounts Info.

Accounts information for ledgers, groups or voucher have the following functions:

Function
 Description
Create
To create new masters.
Display
To view the master information.  Master information cannot be modified in the display mode.
Alter
To view and make changes to the master information. You cannot create masters in the alter mode.

 

Setting F11: Features

To set the F11: Features

1.    Go to Gateway of Tally > F11: Features > F1: Accounts.

2.    Select the company from the List of Companies. The Accounting Features screen appears as shown below:

See F11: Company Features in Tally.ERP 9 for details.

Setting F12: Configure Option

To set F12: Configure

     Go to Gateway of Tally > F12: Configure > Accts / Inventory Info. The Master Configuration screen appears as shown below:

Note: The configurations is applicable for all ledger masters. Changes can be made in the Ledger Configuration screens as well.

Thursday, 14 September 2017 05:50

Creating Masters

Introduction to Creating Masters

You can refer to the topics in the following table for detailed information on creating masters.

Accounts Information

  Groups

Ledgers

Vouchers Types

Inventory Information

 Inventory Configurations and Features

Stock Groups

Stock Categories

Stock Items

Units of Measurement

Bills of Material  Batches and Expiry Date

Wednesday, 13 September 2017 07:19

C - Operator Types

 

What is Operator? Simple answer can be given using expression 4 + 5 is equal to 9. Here 4 and 5 are called operands and + is called operator. C language supports following type of operators.

·         Arithmetic Operators
·         Logical (or Relational) Operators
·         Bitwise Operators·        
.         Assignment Operators
·         Misc Operators

Lets have a look on all operators one by one.

Arithmetic Operators:

There are following arithmetic operators supported by C language:

Assume variable A holds 10 and variable B holds 20 then:

Try following example to understand all the arithmatic operators. Copy and paste following C program in test.c file and compile and run this program.

#include<stdio.h>
#include<conio.h>
main()
{
   int a = 21;
   int b = 10;
   int c ;
   c = a + b;
   printf("Line 1 - Value of c is %d\n", c );
   c = a - b;
   printf("Line 2 - Value of c is %d\n", c )
;
   c = a * b;
   printf("Line 3 - Value of c is %d\n", c );
   c = a / b;
   printf("Line 4 - Value of c is %d\n", c );
   c = a % b;
   printf("Line 5 - Value of c is %d\n", c );
   c = a++;
   printf("Line 6 - Value of c is %d\n", c );
   c = a--;
   printf("Line 7 - Value of c is %d\n", c );
   getch();
}
This will produce following result
Line 1 - Value of c is 31
Line 2 - Value of c is 11
Line 3 - Value of c is 210
Line 4 - Value of c is 2
Line 5 - Value of c is 1
Line 6 - Value of c is 21
Line 7 - Value of c is 22
Operator
Description
Example
+
Adds two operands
A + B will give 30
-
Subtracts second operand from the first
A - B will give -10
*
Multiply both operands
A * B will give 200
/
Divide numerator by denumerator
B / A will give 2
%
Modulus Operator and remainder of after an integer division
B % A will give 0
++
Increment operator, increases integer value by one
A++ will give 11
--
Decrement operator, decreases integer value by one
A-- will give 9

Logical (or Relational) Operators:

There are following logical operators supported by C language

Assume variable A holds 10 and variable B holds 20 then:

Try following example to understand all the Logical operators. Copy and paste following C program in test.c file and compile and run this program.

#include<stdio.h>

#include<conio.h>

main()

{

   int a = 21;

   int b = 10;

   int c ;

   if( a == b )

   {

      printf("Line 1 - a is equal to b\n" );

   }

   else

   {

      printf("Line 1 - a is not equal to b\n" );

   }

   if ( a < b )

   {

      printf("Line 2 - a is less than b\n" );

   }

   else

   {

      printf("Line 2 - a is not less than b\n" );

   }

   if ( a > b )

   {

      printf("Line 3 - a is greater than b\n" );

   }

   else

   {

      printf("Line 3 - a is not greater than b\n" );

   }

   /* Lets change value of a and b */

   a = 5;

   b = 20;

   if ( a <= b )

   {

      printf("Line 4 - a is either less than or euqal to  b\n" );

   }

   if ( b >= a )

   {

      printf("Line 5 - b is either greater than  or equal to b\n" );

   }

   if ( a && b )

   {

      printf("Line 6 - Condition is true\n" );

   }

   if ( a || b )

   {

      printf("Line 7 - Condition is true\n" );

   }

   /* Again lets change the value of  a and b */

   a = 0;

   b = 10;

   if ( a && b )

   {

      printf("Line 8 - Condition is true\n" );

   }

   else

   {

      printf("Line 8 - Condition is not true\n" );

   }

   if ( !(a && b) )

   {

      printf("Line 9 - Condition is true\n" );

   }

}

This will produce following result

Line 1 - a is not equal to b

Line 2 - a is not less than b

Line 3 - a is greater than b

Line 4 - a is either less than or euqal to  b

Line 5 - b is either greater than  or equal to b

Line 6 - Condition is true

Line 7 - Condition is true

Line 8 - Condition is not true

Line 9 - Condition is true

Operator

Description

Example

==

Checks if the value of two operands is equal or not, if yes then condition becomes true.

(A == B) is not true.

!=

Checks if the value of two operands is equal or not, if values are not equal then condition becomes true.

(A != B) is true.

Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true.

(A > B) is not true.

Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true.

(A < B) is true.

>=

Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true.

(A >= B) is not true.

<=

Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true.

(A <= B) is true.

&&

Called Logical AND operator. If both the operands are non zero then then condition becomes true.

(A && B) is true.

||

Called Logical OR Operator. If any of the two operands is non zero then then condition becomes true.

(A || B) is true.

!

Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.

!(A && B) is false.

Bitwise Operators:

Bitwise operator works on bits and perform bit by bit operation.

Assume if A = 60; and B = 13; Now in binary format they will be as follows:

A = 0011 1100

B = 0000 1101

-----------------

A&B = 0000 1100

A|B = 0011 1101

 

A^B = 0011 0001

~A  = 1100 0011

Try following example to understand all the Bitwise operators. Copy and paste following C program in test.c file and compile and run this program.

#include<stdio.h>

#include<conio.h>

main()

{

   unsigned int a = 60;        /* 60 = 0011 1100 */ 

   unsigned int b = 13;        /* 13 = 0000 1101 */

   int c = 0;          

   c = a & b;       /* 12 = 0000 1100 */

   printf("Line 1 - Value of c is %d\n", c );

   c = a | b;       /* 61 = 0011 1101 */

   printf("Line 2 - Value of c is %d\n", c );

   c = a ^ b;       /* 49 = 0011 0001 */

   printf("Line 3 - Value of c is %d\n", c );

   c = ~a;          /*-61 = 1100 0011 */

   printf("Line 4 - Value of c is %d\n", c );

   c = a << 2;     /* 240 = 1111 0000 */

   printf("Line 5 - Value of c is %d\n", c );

   c = a >> 2;     /* 15 = 0000 1111 */

   printf("Line 6 - Value of c is %d\n", c );

}

This will produce following result

Line 1 - Value of c is 12

Line 2 - Value of c is 61

Line 3 - Value of c is 49

Line 4 - Value of c is -61

Line 5 - Value of c is 240

Line 6 - Value of c is 15

There are following Bitwise operators supported by C language

Operator

Description

Example

&

Binary AND Operator copies a bit to the result if it exists in both operands.

(A & B) will give 12 which is 0000 1100

|

Binary OR Operator copies a bit if it exists in eather operand.

(A | B) will give 61 which is 0011 1101

^

Binary XOR Operator copies the bit if it is set in one operand but not both.

(A ^ B) will give 49 which is 0011 0001

~

Binary Ones Complement Operator is unary and has the efect of 'flipping' bits.

(~A ) will give -60 which is 1100 0011

<< 

Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand.

A << 2 will give 240 which is 1111 0000

>> 

Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.

A >> 2 will give 15 which is 0000 1111

Assignment Operators:

There are following assignment operators supported by C language:

Try following example to understand all the Assignment Operators. Copy and paste following C program in test.c file and compile and run this program.

#include<stdio.h>

#include<conio.h>

main()

{

   int a = 21;

   int c ;

   c =  a;

   printf("Line 1 - =  Operator Example, Value of c = %d\n", c );

   c +=  a;

   printf("Line 2 - += Operator Example, Value of c = %d\n", c );

   c -=  a;

   printf("Line 3 - -= Operator Example, Value of c = %d\n", c );

   c *=  a;

   printf("Line 4 - *= Operator Example, Value of c = %d\n", c );

   c /=  a;

   printf("Line 5 - /= Operator Example, Value of c = %d\n", c );

   c  = 200;

   c %=  a;

   printf("Line 6 - %= Operator Example, Value of c = %d\n", c );

   c <<=  2;

   printf("Line 7 - <<= Operator Example, Value of c = %d\n", c );

   c >>=  2;

   printf("Line 8 - >>= Operator Example, Value of c = %d\n", c );

   c &=  2;

   printf("Line 9 - &= Operator Example, Value of c = %d\n", c );

   c ^=  2;

   printf("Line 10 - ^= Operator Example, Value of c = %d\n", c );

   c |=  2;

   printf("Line 11 - |= Operator Example, Value of c = %d\n", c );

}

This will produce following result

Line 1 - =  Operator Example, Value of c = 21

Line 2 - += Operator Example, Value of c = 42

Line 3 - -= Operator Example, Value of c = 21

Line 4 - *= Operator Example, Value of c = 441

Line 5 - /= Operator Example, Value of c = 21

Line 6 - %= Operator Example, Value of c = 11

Line 7 - <<= Operator Example, Value of c = 44

Line 8 - >>= Operator Example, Value of c = 11

Line 9 - &= Operator Example, Value of c = 2

Line 10 - ^= Operator Example, Value of c = 0

Line 11 - |= Operator Example, Value of c = 2

Operator

Description

Example

=

Simple assignment operator, Assigns values from right side operands to left side operand

C = A + B will assigne value of A + B into C

+=

Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand

C += A is equivalent to C = C + A

-=

Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand

C -= A is equivalent to C = C - A

*=

Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand

C *= A is equivalent to C = C * A

/=

Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand

C /= A is equivalent to C = C / A

%=

Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand

C %= A is equivalent to C = C % A

<<=

Left shift AND assignment operator

C <<= 2 is same as C = C << 2

>>=

Right shift AND assignment operator

C >>= 2 is same as C = C >> 2

&=

Bitwise AND assignment operator

C &= 2 is same as C = C & 2

^=

bitwise exclusive OR and assignment operator

C ^= 2 is same as C = C ^ 2

|=

bitwise inclusive OR and assignment operator

C |= 2 is same as C = C | 2

Short Notes on L-VALUE and R-VALUE:

x = 1; takes the value on the right (e.g. 1) and puts it in the memory referenced by x. Here x and 1 are known as L-VALUES and R-VALUES respectively L-values can be on either side of the assignment operator where as R-values only appear on the right.

So x is an L-value because it can appear on the left as we've just seen, or on the right like this: y = x; However, constants like 1 are R-values because 1 could appear on the right, but 1 = x; is invalid.

Misc Operators

There are few other operators supported by C Language.

Try following example to understand all the Assignment Operators. Copy and paste following C program in test.c file and compile and run this program.

 

#include<stdio.h>

#include<conio.h>

main()

{

   int a = 21;

   int c ;

   c =  a;

   printf("Line 1 - =  Operator Example, Value of c = %d\n", c );

   c +=  a;

   printf("Line 2 - += Operator Example, Value of c = %d\n", c );

   c -=  a;

   printf("Line 3 - -= Operator Example, Value of c = %d\n", c );

   c *=  a;

   printf("Line 4 - *= Operator Example, Value of c = %d\n", c );

   c /=  a;

   printf("Line 5 - /= Operator Example, Value of c = %d\n", c );

   c  = 200;

   c %=  a;

   printf("Line 6 - %= Operator Example, Value of c = %d\n", c );

   c <<=  2;

   printf("Line 7 - <<= Operator Example, Value of c = %d\n", c );

   c >>=  2;

   printf("Line 8 - >>= Operator Example, Value of c = %d\n", c );

   c &=  2;

   printf("Line 9 - &= Operator Example, Value of c = %d\n", c );

   c ^=  2;

   printf("Line 10 - ^= Operator Example, Value of c = %d\n", c );

   c |=  2;

   printf("Line 11 - |= Operator Example, Value of c = %d\n", c );

}

This will produce following result

Line 1 - =  Operator Example, Value of c = 21

Line 2 - += Operator Example, Value of c = 42

Line 3 - -= Operator Example, Value of c = 21

Line 4 - *= Operator Example, Value of c = 441

Line 5 - /= Operator Example, Value of c = 21

Line 6 - %= Operator Example, Value of c = 11

Line 7 - <<= Operator Example, Value of c = 44

Line 8 - >>= Operator Example, Value of c = 11

Line 9 - &= Operator Example, Value of c = 2

Line 10 - ^= Operator Example, Value of c = 0

Line 11 - |= Operator Example, Value of c = 2

Operator

Description

Example

sizeof()

Returns the size of an variable.

sizeof(a), where a is interger, will return 4.

&

Returns the address of an variable.

&a; will give actaul address of the variable.

*

Pointer to a variable.

*a; will pointer to a variable.

? :

Conditional Expression

If Condition is true ? Then value X : Otherwise value Y

Operators Categories:

All the operators we have discussed above can be categorised into following categories:

·         Postfix operators, which follow a single operand.

·         Unary prefix operators, which precede a single operand.

·         Binary operators, which take two operands and perform a variety of arithmetic and logical operations.

·         The conditional operator (a ternary operator), which takes three operands and evaluates either the second or third expression, depending on the evaluation of the first expression.

·         Assignment operators, which assign a value to a variable.

·         The comma operator, which guarantees left-to-right evaluation of comma-separated expressions.

Precedence of C Operators:

Operator precedence determines the grouping of terms in an expression. This affects how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has higher precedence than the addition operator:

For example x = 7 + 3 * 2; Here x is assigned 13, not 20 because operator * has higher precedenace than + so it first get multiplied with 3*2 and then adds into 7.

Here operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom. Within an expression, higher precedenace operators will be evaluated first.

Category 

Operator 

Associativity 

Postfix 

() [] -> . ++ - -  

Left to right 

Unary 

+ - ! ~ ++ - - (type) * & sizeof 

Right to left 

Multiplicative  

* / % 

Left to right 

Additive  

+ - 

Left to right 

Shift  

<< >> 

Left to right 

Relational  

< <= > >= 

Left to right 

Equality  

== != 

Left to right 

Bitwise AND 

Left to right 

Bitwise XOR 

Left to right 

Bitwise OR 

Left to right 

Logical AND 

&& 

Left to right 

Logical OR 

|| 

Left to right 

Conditional 

?: 

Right to left 

Assignment 

= += -= *= /= %= >>= <<= &= ^= |= 

Right to left 

Comma 

Left to right 

Friday, 01 September 2017 07:50

Types of program translator

Assembler

An assembler translates assembly language into machine code. Assembly language consists of mnemonics for machine opcodes so assemblers perform a 1:1 translation from mnemonics to a direct instruction. For example:

LDA #4 converts to 0001001000100100

Conversely, one instruction in a high level language will translate to one or more instructions at machine level.

Advantages of using an Assembler:

plus pointVery fast in translating assembly language to machine code as 1 to 1 relationship
plus pointAssembly code is often very efficient (and therefore fast) because it is a low level language
plus pointAssembly code is fairly easy to understand due to the use of English-like mnemonics


Disadvantages of using Assembler:

minus point Assembly language is written for a certain instruction set and/or processor
minus point Assembly tends to be optimised for the hardware it's designed for, meaning it is often incompatible with different hardware
minus point Lots of assembly code is needed to do relatively simple tasks, and complex programs require lots of programming time

 

 

Compiler

Compiler is a computer program that translates code written in a high level language to a lower level language, object/machine code. The most common reason for translating source code is to create an executable program (converting from a high level language into machine language).

Advantages of using a compiler

plus pointSource code is not included, therefore compiled code is more secure than interpreted code
plus pointTends to produce faster code than interpreting source code
plus pointProduces an executable file, and therefore the program can be run without need of the source code


Disadvantages of using a compiler

minus point Object code needs to be produced before a final executable file, this can be a slow process

 

minus point The source code must be 100% correct for the executable file to be produced

Interpreter

An interpreter program executes other programs directly, running through program code and executing it line-by-line. As it analyses every line, an interpreter is slower than running compiled code but it can take less time to interpret program code than to compile and then run it — this is very useful when prototyping and testing code. Interpreters are written for multiple platforms, this means code written once can be run immediately on different systems without having to recompile for each. Examples of this include flash based web programs that will run on your PC, MAC, games console and Mobile phone.

Advantages of using an Interpreter

plus pointEasier to debug(check errors) than a compiler
plus pointEasier to create multi-platform code, as each different platform would have an interpreter to run the same code
plus pointUseful for prototyping software and testing basic program logic


Disadvantages of using an Interpreter

minus point Source code is required for the program to be executed, and this source code can be read making it insecure
minus point Interpreters are generally slower than compiled programs due to the per-line translation method
Friday, 01 September 2017 07:14

Generations of programming language

There are many types of programming languages out there and you might already have heard of a few of them, for example: C++, VB.NET, Java, Python, Assembly. We will now look at the history of how these languages came about and what they are still useful for. In all cases keep in mind that the only thing a computer will execute is machine code or object code when it has been converted from a language to run on a processor.

Generation First Second Third Fourth
Code example

10101010011000101
10011010100000010
11111111101000101

LDA 34
ADD #1
STO 34
x = x + 1
body.top { color : red;
           font-style : italic
}
Language (LOW) Machine Code (LOW) Assembly Code (HIGH) Visual Basic, C, python etc. (HIGH) SQL, CSS, Haskell etc.
Relation to Object Code
(generally)
-- one to one one to many one to many

First generation

 
The Colossus Mark 2 was the world's first electronic digital programmable computer. Operators had to write the machine code directly by setting switches.

The first generation program language is pure machine code, that is just ones and zeros, e.g.{\displaystyle 0010010010101111101010110}. Programmers have to design their code by hand then transfer it to a computer by using a punch card, punch tape or flicking switches. There is no need to translate the code and it will run straight away. This may sound rather archaic, but there are benefits:

plus pointCode can be fast and efficient
plus pointCode can make use of specific processor features such as special registers


And of course drawbacks

minus point Code cannot be ported to other systems and has to be rewritten

 

minus point Code is difficult to edit and update
 

Second generation programming

Second-generation programming languages are a way of describing Assembly code which you may have already met.

By using codes resembling English, programming becomes much easier. The usage of these mnemonic codes such as LDA for load and STA for store means the code is easier to read and write. To convert an assembly code program into object code to run on a computer requires an Assembler and each line of assembly can be replaced by the equivalent one line of object (machine) code:

Assembly Code   Object Code
LDA A
ADD #5
STA A
JMP #3

-> Assembler ->

000100110100
001000000101
001100110100
010000000011

Assembly code has similar benefits to writing in machine code, it is a one to one relationship after all. This means that assembly code is often used when writing low level fast code for specific hardware. Until recently machine code was used to program things such as mobile phones, but with the speed and performance of languages such as C being very close to Assembly, and with C's ability to talk to processor registers, Assembly's use is declining.

As you can hopefully see there are benefits to using Second-Generation Languages over First-Generation, plus a few other things that makes Assembly great:

plus pointCode can be fast and efficient
plus pointCode can make use of specific processor features such as special registers
plus pointAs it is closer to plain English, it is easier to read and write when compared to machine code


And of course drawbacks

 

minus point Code cannot be ported to other systems and has to be rewritten
 

Third generation (High Level Languages)

Even though Assembly code is easier to read than machine code, it is still not straight forward to perform loops and conditionals and writing large programs can be a slow process creating a mish-mash of goto statements and jumps. Third-generation programming languages brought many programmer-friendly features to code such as loops, conditionals, classes etc. This means that one line of third generation code can produce many lines of object (machine) code, saving a lot of time when writing programs.

Imperative languages - code is executed line by line, in a programmer defined sequence


Third generation (High Level Languages) codes are imperative. Imperative means that code is executed line by line, in sequence. For example:

1 dim x as integer
2 x = 3
3 dim y as integer
4 y = 5
5 x = x + y
6 console.writeline(x)

Would output: 8

Third generation languages can be platform independent, meaning that code written for one system will work on another. To convert a 3rd generation program into object code requires a Compiler or an Interpreter.

To summarise:

plus pointHardware independence, can be easily ported to other systems and processors
plus pointTime saving programmer friendly, one line of 3rd gen is the equivalent of many lines of 1st and 2nd gen


However

minus point Code produced might not make the best use of processor specific features unlike 1st and 2nd gen

 

Extension: Programming Paradigms

There are several types of Third-generation languages that you will cover in more detail at A2. They include:

  • Object Orientated
  • Event driven

Fourth generation

Fourth-generation languages are designed to reduce programming effort and the time it takes to develop software, resulting in a reduction in the cost of software development. They are not always successful in this task, sometimes resulting in inelegant and hard to maintain code. Languages have been designed with a specific purpose in mind and this might include languages to query databases (SQL), languages to make reports (Oracle Reports) and languages to construct user interface (XUL). An example of 4th generation programming type is the declarative language.

--an example of a Structured Query Language (SQL) to select criminal details from a database
SELECT name, height, DoB FROM criminals WHERE numScars = 7;

Declarative languages - describe what computation should be performed and not how to perform it. Not imperative!

 

An example of a declarative language is CSS which you might learn more about when completing any web design unit

 

/*code to change the headings on a page to green and the paragraphs to red and italic*/
h1 { color : #00FF00; }
p { color : #FF0000; font-style : italic }
Page 2 of 31