Tuesday 27 March 2018

Some Most Popular Programming Language

FORTRAN (FORmula TRANslation)
 The name FORTRAN is an acronym for FORmula TRANslation, because it was designed to allow easy translation of math formulas into code.
Often referred to as a scientific language, FORTRAN was the first high-level language, using the first compiler ever developed.Prior to the development of FORTRAN computer programmers were required to program in machine/assembly code, which was an extremely difficult and time consuming task.
The objective during it's design was to create a programming language that would be: simple to learn, suitable for a wide variety of applications, machine independent, and would allow complex mathematical expressions, machine independent, and would allow complex mathematical expressions to be stated similarly to regular algebraic notation. 

COBOL (Common Business Oriented Language)
 COBOL (pronounced / ? ko?b?1/) is one of the oldest programming languages.Its name is an acronym for Common Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments.
The COBOL 2002 standard includes support for object-oriented programming and other modern language features. 
COBOL was an effort to make a programming language that was like natural English, easy to write and easier to read the code after you'd written it.

BASIC (Beginner's All-purpose Symbolic Instruction Code)
 In computer programming, BASIC ( an acronym for Beginner's All-purpose Symbolic Instruction Code) is a family of high-level programming languages.
It is developed to provide computer access to non-science students.
BASIC remains popular to this day in a handful of highly modified dialects and new languages influenced by BASIC such as Microsoft Visual Basic.As of 2006, 59 % of developers for the .NET platform used Visual Basic .NET as their only language.

PASCAL
 Pascal is an influential imperative and procedural programming language designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structuring.
A derivative known as Object Pascal was designed for object oriented programming.

C Language
 C is a general-purpose computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system.
Although C was designed for implementing system software, it is also widely used for developing portable application software.
C is one of the most popular programming languages. It is widely used on many different software platforms.

C++ Language
 C++ (pronounced "C plus plus") is a statically typed, free -form multi-paradigm, compiled, general-purpose programming language.
It is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features.
It was developed by Bjarne Stroustrup starting in 1979 at Bell Labs as an enhancement to the C programming language and originally named "C with Classes". It was renamed to C++ in 1983.

JAVA
 Java is a programming language originally developed by James Gosling at Sun Micro-systems and released in 1995 as a core component of Sun Micro system Java platform.
The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities.
Java application are typically compiled to byte-code (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture. 

LISP (LISt Processing)
 Lisp (or LISP) is a family of computer programming languages.
It is the second-oldest high-level programming language in widespread use today.
Lisp was originally created as a practical mathematical notation for computer programs.
The name LISP derives from "LISt Processing" .Linked lists are one of Lisp languages major data structures, and Lisp source code is itself made up of lists.

High-level Programming Language Tools : Compiler , Linker , Interpreter


Compiler 

 Compiler is used to transform a program written in a high-level programming language from source code into object code.

Programmers write programs in a form called source code.Source code must go through several steps before it becomes an executable program.

The first step is to pass the source code through a compiler, which translates the high-level language instructions into object code.

The final step in producing an executable program--after the compiler has produced object code-- is to pass the object code through a linker. The linker combines modules and gives real values to all symbolic addresses, thereby producing machine code.

Linker

 Also called link editor  and binder, a linker is a program that combines objects modules to form an executable program.

Many programming languages allow you to write different pieces of code, called modules, separately.

This simplifies the programming task because you can break a large program into small, more manageable pieces.

Eventually, through you need to put all the modules together.This is the job of the linker.

Interpreter

 An interpreter translates high-level instructions into an intermediate form which it then executes.

Compiled programs generally run faster than interpreted programs.

The advantage of an interpreter, however, is that it does not need to go through the compilation stage during which machine instructions are generated.The process can be time-consuming if the program is long.

The interpreter, on the other hand, can immediately execute high-level programs.

Editor

 An editor is software, where the programmer can write the source code, edit it as well as compile and execute it. Like compilers and interpreters, the editors are also different for different programming languages.

MATLAB

  MATLAB (MATrix LABoratory) is a numerical computing environment and fourth generation programming language, developed by the Math works.

 MATLAB allows matrix manipulation plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs in other languages.

GUI (Graphical User Interface)
 GUI is a program interface that takes advantage of the computer's graphics capabilities to make the program easier to use. Well-designed graphical user interfaces can free the user from learning complex command languages.

Jumps out of the Loop

The break statement
  As we have already seen, the 'break' statement is used to exit out of the switch statement.It is having another useful application in loop control structures.That is, the 'break' statement is used to jump out of the loop.When the 'break' is executed inside the loop, the program control will not execute the loop for further iterations.Generally,   the 'break' is associated with if-statement.
General form of using 'break' is :-
break;


The dotted line shows the path where the Program control will transfer.
For example:
/*Example*/
int x;
for(x = 10; x<20; x++)
{
if(x%4 ==0)
break;
printf("%d\n",x);
}

The output of this program will be:
10
11
Because, when value of x becomes 12, the condition will be evaluated to true and break get executed.

The 'continue' statement
  The continue statement is used continue the next iteration of the loop by skipping the statements in between.That is, when the 'continue' is executed the statements following is will not be executed, the program control will directly transfer to next iteration of the loop by increment or decrement.Generally, the 'continue' is associated with if-statement.General form of using 'continue' is-
continue;

The dotted line shows the path where the program control will transfer.
For Example:-
int x;
for(x = 10; x < 20; x++)
{
if(x%4 ==0)
continue;
printf("%d");
}

The output of this program will be:
10   11   13  14  15  17  18  19

The 'switch' Statement
This is another form of the multi-way decision statement.It is well structured, but can only be used in certain cases. The switch statement tests value of a given variable (or expression) against the list of case values and when the match is found, a block of statements associated with that statements are executed. The general form of switch statement is as follows:
switch(variable)
{
case value-1:
//statement 1;
break;
case value-2:
//statements 2;
break;
case value-3
//statements 3
break;
--------
default:
//default-statements;
break;
}
statements-x;
In the above given syntax, value-1, value-2, value3..... are the set the constants. When the value of the variable given in the switch brackets is matched with any one of these values, the particular set of statements are executed and then program control transfer out of the switch block. For example, if value of variable is matched with 'value-2' then statements2 are executed and the break statement transfer the program control out of the switch.If the match is not found, the 'default' block is executed. Remember, statements-x are executed in any case. Generally, switch case are executed for menu selection problems.


Rules of switch statement
1. The switch variable must be an integer or character type.
2. Case labels must be constants of constants expressions.
3. Case labels must be unique. No two labels can have the same value.
4. Case labels must end with a colon.
5. The break statement transfers the program control out of the switch block.
6. The break statement is optional. When the break is not written in any 'case' then the statements following the next case are also executed until the 'break' is not found.
7. The default case is optional. If present, it will be executed when the match with any 'case' is not found.
8. There can be at most one default label.
9. The default may be placed anywhere but generally written at the end . When placed at end it is not compulsory to write the 'break' for it.
10. We can nest the switch statements.

Monday 26 March 2018

The Loop control Structures

Many times it is necessary to execute several statement repetitively for certain number of times. In such case, we can use looping statement of Cpp programming language. The statement are executed until a condition given is satisfied. Depending upon the position of the condition in the loop, the loop control structures are classified as the entry-controlled loop and exit-controlled loop. They are also called as pre-test and post-test loops respectively.

The 'while' loop
   The 'while' is an entry-controlled loop statement having following general form:
   while(condition)
    {
      //loop statement or body of loop
     }
        Here, the condition is evaluated first,if it is true then loop statements or body of the loop is executed.After this the program control will transfer to condition again to check whether it is true or false.If true,again loop body is executed.This process will be continued until the condition becomes false.When is becomes false, the statements after the loop are executed.This is also called as pre-test loop. 


The do-while loop
  This 'do-while' is exit-controlled loop statement in which the condition of the loop statement is written at the end of the loop.It takes the following general form:
    do
     {
      //loop statement or loop body
     }while(condition)
Here, when the program control is reached at do statement the loop body or statements inside the loop are executed first.Then at the end the condition is the 'while' is checked.If it is true, then program control again transfers to execute the loop statements.This process continues until the condition becomes false.In short, we can say that the loop statements are executed at least once without checking condition for its trueness.


     
The 'For' loop
  The 'for' loop is an entry controlled loop structure which provides more concise loop structure having following general form:
  for(initialization ; condition ; increment/decrement)
  {
   //loop statement or loop body
   }
 The execution of 'for' loop statement takes as follows:
  1. Initialization of loop control variables is done first using assignment operators such as: i= 1 or count = 0 etc. Remember this part is executed only once.
  2. The condition given afterwards is checked then. If this condition is true, the statements inside the loop are executed.Else program control will get transferred nest statement after the loop.The condition can be combination of relational as well as logical operators such as :
count < 10
  3. When the body of the loop is executed, program control will get transferred back to 'for' statement for executing the third statement that is, 'increment/decrement'. In this part the loop control variable's value is incremented or decremented.Then program controls the condition again to check whether it is true or not. If true the loop body executed again.And the process is continued again until condition evaluates to false.

Sunday 25 March 2018

Decision Making Statements

Many times in the program such condition occur when we want to take the exact decisions in order to make an error free program.This kind of situation can be handled using decision control instruction of cpp.It includes if-else statements and the conditional operators.The  decision control structure in cpp can be implemented using:
a) The if statements 
b) The if-else statement
c)  Nested if-else 
d) The else-if ladder

The if Statement
  The general form or syntax of if statement looks like this:
   if(condition)'
    {
      statement-1;
     }
      statement-2;
      statement-3;
     

Here, the keyword 'if' tells the compiler that what follows, is a decision control instruction.The condition following the keyword if is always enclosed within a pair of parentheses.It the condition is true, then the statement in the parenthesis are executed.It the condition is not true then the statement is not executed instead the program skips this part.


The if-else statement 
   The 'if' statement by itself will executed a single statement or a group of statement when the condition following if is true,it does nothing when the condition is false.If the condition is false then a group of statement can be executed using 'else' statement.Its syntax is as given below:

if(condition)
 {
  // statements 1
  }
   else
    {
     // statements 2
     }
    Statement3;


When, we used if-else statement, either 'if' or 'else' statement block will execute depending upon the condition given in the 'if' statement.The 'else' doesn't require condition.Execution of 'else' block also depends on if(condition). When it is false program control transfer to 'else' block.

Nested if-else
 If we write an entire if-else construct within the body of the 'if' statement or the body of an 'else' statement. This is called 'nesting' of if else.

Syntax:
 if(condition)
 {
   //statements1
   if(condition)
    {
     //statements2
     }
     else
     {
      //statements3
      }
   }
 else
 //statements4
 Here,the inner condition executed only when the outer condition of 'if' is true.This hierarchy of nesting of 'of' can be extended in deep with any number of 'if-else' statements.

The else-if ladder
  There is another way of putting multiple 'if's together when multipath decisions are involved. A multipath decision is a chain of 'if's which the statement is associated with each else in an 'if'. It takes the following general form:

if(condition1)
//statements1;
else if(condition2)
//statements2;
else if(condition3)
//statements3;
else if(condition n)
//statements n;
else
//statements-x;
                         This construct is known as else-if ladder.The condition are evaluated from top to the bottom of ladder.As soon as true condition is found, statements associated with it are executed and then program control  is transferred to the 'statements-x' , skipping the rest of the ladder.
  When all the condition become false, then final else containing default statements will be executed.This is shown in the following flowchart-


Types of Programming Languages

We classify programming language by their level.
a) Natural Language.
b) Machine level Language
c) High-level Language
d) Assembly level Language
e) Scripting Language

Natural Language
  A language spoken, written or signed by humans for general purpose communication.

Machine Level Language
  It is the lowest-level programming language.
  Machine language are the only language understood by computers.
  Programs written in high-level language are translated into machine language by a compiler.
  A computer's language consists of strings of binary numbers (0,1).

Limitations 
 - In this programming language a programmer has to remember dozens of code numbers or commands in the machine instruction set.
- A programmer has to keep track of the storage locations of data and instructions.
- Modifications of a machine level program and the location of errors in it is a tedious job and can take long time.

Assembly Level Language
  The assembly language is simply a symbolic representation for its associated machine language.
  This representation consists of mnemonic operation codes and symbolic address.
Advantage
 - Less number of errors and also errors are easy to find.
 - Modification of assembly language program is easier than that of machine language program.
Limitation
 - They are machine oriented.

High Level Language (HLL)
  A programming language such as c, FORTRAN, or Pascal that enables programmer to write programs that are more or less independent of a particular type of computer. Such language are considered high-level because they are closer human languages and further from machine languages.

Characteristics of High Level Programming Language
  In computing, a high-level programming language is a programming language with strong abstraction from the details of the computer.
 In comparison to low-level programming language, it may use natural language elements, be easier to use, or be more portable across platforms.
 Such language hide details of CPU operations such as memory access models and management of scope

Scripting Language
  A scripting language is a high-level programming language that is interpreted by another program at runtime rather than compiled by the computer's processor as other programming language (such as C and C++) are.
 Scripting language, which can be embedded within HTML, commonly are used to add functionality to a web page, such as different menu styles or graphic displays or to serve dynamic advertisements. 

What is Programming Language ?

A Programming language is nothing but a vocabulary and set of grammatical rules for instructing a computer to perform specific tasks. The term Programming language usually refers to high-level language, such as BASIC, C, C++.

High-level programming language are more complex than the languages the computer actually understands,called machine language.

Lying between machine language and high-level language are languages called assembly language. Assembly language allow a programmer to substitute names instead of numbers as in machine languages.

Lying above high-level language are languages called fourth-generation languages (usually abbreviated 4GL), represents the class of computer language closest to human languages.

Structure of C++ Program

A C++ program consist four sections as shown in following fig.This section may be placed in a separate code files and then compiled independently or jointly.


Section I : Header File Declaration Section
  1. Header Files used in the program are listed here.
  2. Header files provides prototype declarations for different library functions.
  3. Basically all preprocessor directives are written in this section.

Section II : Global Declaration Section
  1. Global Variables are declared here.
  2. Global Declaration include
       Declaring structure
       Declaring class
       Declaring variable.

Section III : Class Declaration Section 
   1. Actually this section can be considered as a sub section for the global declaration section.
   2. Class declaration and all method of that class are defined here.

Section IV : main Function
  1. Each and every cpp program always starts with main function.
  2. This is the entry point for the functions.Each and every method is called indirectly through main.
  3.We can create class object in the main.
  4. Operating system call this function automatically.

This approach is based on client server model as shown in figure.
  This class definition including member function constitute the server that provides the service to the main program known as a client.
  Client uses the server through public interface class.

Simple C++ Program
//Program to print String
#include<conio.h>
#include<iostream.h>
class first
{
  public:
  void display()
  {
   cout<<"Welcome to the world of C++";
   }
};
 void main()
 {
  first f;
  f.display();
  getch();
}

Output-
    Welcome to the world of C++

Derived Data Types

Derived data type is a data type which is derived from primitive data type.
Ex: Array is a collection of homogeneous types of element and it stores elements at adjacent memory locations called as contiguous memory locations.
Syntax:
Data type name_of_array[size];

Ex:
int arr[10];
This array stores ten integer types of element at adjacent memory locations.
arr[0]  arr[1]  arr[2]  arr[3]  arr[4]  arr[5]  arr[6]  arr[7]  arr[9].

\* Write a program to implement array */
#include<conio.h>
#include<stdio.h>
void main()
{
int a[5]={10,20,30,40,50};
int i;
clrscr();
printf("\n\n\tElements in forward direction is -->\n\n");
for(i=0;i<5;i++)
{
printf("\t%d",a[i]);

}
printf("\n\n\tElements in Backward Direction is-->\n\n");
for(i=4;i>=0;i--)
{
printf("\t%d",a[i]);
}
getch();
}

Output-
     Elements in forward direction is -->
      10   20   30   40   50
     Elements in Backward Direction is-->
      50   40   30   20   10

User Defined data types

Structure 
  Structure is a collection of variables of different data types grouped together under a single name.
         Each variable within a structure is called as member of structure.

Syntax of defining structure :-
     struct structure_name
      {
        Structure_member 1;
        Structure_member 2;
        ...............................
       ................................
       Structure_member n;
        }instances;

           OR

   struct structure_name
   {
      Structure_member 1;
      Structure_member 2;
        ...............................
       ................................
       Structure_member n;
        };
          struct structure_name instance;

Ex-
 struct student
  {
    char name[20];
    int rollno;
    float per;
   }stud1,stude2;
                   OR
  
 struct student
  {
    char name[20];
    int rollno;
    float per;
   } 
 struct student stud1,stud2;

Initialization of structure Variable:
   
An instance of a structure can be assigned values during declaration as follows.
        struct student
        {
          char name[20];
          int rollno;
         float per;
        }stud1={"irawen",101,78.12};

Accessing Structure Member:
   Individual members of structure can be used like other variables. Structure member can be assessed by dot operator(.).
 This dot operator (.) is used between the structure name and member name.
   Ex- stud1.name , stud1.rollno , stud1.per
values can also be assigned to structure member.
     stud1.name="irawen";
     stud1.rollno=101;
     stud1.per=78.12;

Question 1) Write a program to define structure 'Tender' having data member tender_no,cost and company_name.Accept and display data for one variable of the structure.

#include<conio.h>
#include<iostream.h>
struct Tender
{
  int tender_no;
  float cost;
  char company_name[20];
};
void main()
{
Tender t1;
clrscr();
cout<<"\tEnter Tender Number";
cin>>t1.tender_no;
cout<<"\nEnter Cost of Tender";
cin>>t1.cost;
cout<<"\nEnter Company Name";
cin>>t1.company_name;
cout<<"\n\n\tTender Number is →"<<t1.tender_no;
cout<<"\n\n\tTender cost is→"<<t1.cost;
cout<<"\n\n\tCompany Name is→"<<t1.company_name;
getch();
}

Output-
  Enter Tender Number101
  Enter Cost of Tender1234
  Enter Company NameIrawen.info
                          Tender Number is→101
                          Tender cost is→1234
                          Tender Name is→Irawen.info 

Union :
    Union are a concept borrowed from structures and therefore the same syntax as structure.
          But here is a major difference between them is in storage structures. In structure there is a separate storage memory location for each data member where all the member of union share the memory locations.
Ex-
  Union item
   {
     int a;
     float b;
     char c;
   } it;

Example Union-
#include<conio.h>
#include<stdio.h>
void main()
{
union item
 {
   int m;
   float p;
   char ch;
  }it;
clrscr();
it.m=12;
it.p=23.12;
it.ch='A';
printf("\n\n\tItem No is→%d",it.m);
printf("\n\n\tPrice is→%f",it.p);
printf("\n\n\tStarting character of item is→%c",it.ch);
getch();
}

Output-
    Item No is→2751
    Price is→23.119753
    Starting character of item is→A

Enumerated Data Types:-
   An enumerated data type is another user defined type which provides a way of attaching names to the members.
The enum keyword automatically enumerates the list of words by assigning values 0,1,2.....and so on.
    Syntax:   
          enum shape{circle.square,triangle};
          enum color{red,blue,green,yellow};
         :Declaring Variable of enum:
        Ex.shape ellipse;color background;
By default enum assigns integer values starting with '0' zero for the first enumerator,1 for the second and so on..
 We can over ride the default by just assigning integer values to enumerator.
  enum color{red,blue=4,green=3};
  enum color{red=5,blue,green};

#include<iostream.h>
#include<conio.h>
void main();
{
 enum color{red,blue,green};
 enum color1{red1,blue1=4,green1=6};
 cout<<"\n\n\tColor of Background-->"<<red;
 cout<<"\n\n\tColor of Background-->"<<blue;
  cout<<"\n\n\tColor of Background-->"<<green;
  cout<<"\n\n\tColor of Background-->"<<red1;
  cout<<"\n\n\tColor of Background-->"<<blue1;
  cout<<"\n\n\tColor of Background-->"<<green1;
  getch();
}

Output-
      Color of Background-->0
      Color of Background-->1
      Color of Background-->2
      Color of Background-->0
      Color of Background-->4
      Color of Background-->6

Saturday 24 March 2018

What is C languages ?

C is a very powerful and widely used language. It is used in many scientific programming situations. It forms (or is the basis for) the core of the modern languages Java and C++. It allows you access to the bare bones of your computer.


High Level Language:-
  BASIC :
      Beginner's all-purpose symbolic instruction code
      Used only for small general purpose application
  COBOL :
       Common Business Oriented Language
       Used for business applications only
  FORTRAN :
       Formula Translation
       Used only for engineering applications
  PASCAL :
       These specific language for specific software
       If we want to go to America we must know English Language


Low Level Language:-
  It is a machine level language
  Understandable for computer in 0 1 0 1 0 1 form
  In earlier days this language is used for giving commands computer in 0101010100101010101 format.




Middle Level Language :-
  Middle-level language (MLL) is a computer programming language that interacts with the abstraction layer of a computer system.
  It has both features of HLL and LLL
  It translates the human readable language into Machine language and vice versa
  It not only used to write application software but also system software and communication with hardware.


Basic Knowledge about Software

What is Computer ?
  → Computer is an electronic device that takes input, process it and gives output.

What is 0 and 1 ?
  → There is nothing like 0 and 1 in computer.There is no physical significance of 0 and 1
  → Any information can be encoded as a sequence of 0 and 1.

How 0 and 1 get stored in memory ?
What is Hardware ?
 → Hardware is a comprehensive term for all of the physical parts of a computer, as distinguished from the data it contains or operates on, and the software that provides instruction for the hardware to accomplish tasks
    Hardware is anything which is tangible.

What is a File ?
   File is a data bundle.


What is software ?
  Application Software
  System Software

Program and Process
    Set of instruction is called Program
    Active state of a program is called Process

Operating System
   It is a system software
   Examples are DOS, windows xp, windows vista, windows 7 windows 8, Solaris, Macintosh, Linux, ubuntu etc.
It provides interface between user and machine.
Acts as a manger of the computer system
It does process management, memory management, file management.

Execution of Program


Software develop in C language


Why C language is Important ?

Why C language is so important ?
  • Worth to know about C language
              - Oracle is written in C
              - Core libraries of android are written in C
              - MySQL is written in C
              - Almost every device driver is written in C
              - Major part of web browser is written in C
              - Unix operating system is developed in C
              - C is the world's most popular programming language
   
  • For Students  
              - C is important to build programming skills
              - C covers basic features of all programming language 
              - C campus recruitment process
              - C is most popular language for hardware dependent programming
             
  • History of C language
            It is Developer of BCPL
            Basic Combined Programming Language
            It is develop in 1966


Developer of B language
It is develop in 1969.Also developer of UNIX operating system 
He is also developed first master level chess called Belle in 1980.

Developer of C language in 1972.
At AT & T's Bell LABs, USA
Co-developer of UNIX operating system


Recursion

Recursive function is a function that calls itself. When a function calls another function and that second function calls the third function then this kind of a function is called nesting of functions.But a recursive is the function that calls itself repeatedly.

A simple example :
main ( )
{
printf (" this is an example of recursive function");
main( );
}
 when this program is executed.The line is printed repeatedly and indefinitely.We might have to abruptly terminate the execution.

/*Program to calculate Factorial of a number */
#include <stdio.h>
void calc_factorial (int);  //function prototype
void calc_factorial (int i)
{
int I, factorial_number = 1;
for (i = 1; I < = n; ++i)
   factorial_number *=I;
printf("The factorial of %d is %d\n", n, factorial_number);
}
int main(void)
{
int number = 0;
printf(" Enter a number\n");
scanf("%d",&number);
calc_factorial (number);
return 0;
}

Sample Program Output
  Enter a number
     3
   The factorial of 3 is 6

Friday 23 March 2018

Function

A function is a self contained block of statement that perform a coherent task of some kind.
Function provides modularity to the software.

Function definition :
[data type] function name (argument list)
argument declaration;
{
local variable declaration;
statements;
[return expression]
}

Example :
mul(a,b)
int a,b;
{
int y;
y = a + b;
return y;
}
When the value of y which is the addition of the values of a and b.The last two statement i.e.,
y = a + b; can be combined as
return (y)
return (a + b)

Why Functions are used ?
  1. Many program require that a specific function is repeated many times instead of writing the function code as many timers as it is required we can write it as a single function and access the same function again as many times as it is required.
  2. We can avoid writing redundant program code  of some instructions again and again.
  3. Programs with using functions are compact and easy to understand.
  4.Testing and correcting errors is easy because errors are localized and corrected.
  5.We can understand the flow of program and its code easily since the readability in enhanced while using the functions.
  6. A single function written in a program can also be used in other programs also.

#include <stdio.h>
/* function body */
int add (int x, int y){
 int z;
z = x + y;
return (z);
}
main ( )
{
int i,j,k;
i = 10;
j = 20;
k = add(i,j);  /* function call */
printf ("The value of k is %d\n",k);
}
The value of k is 30

Scope Resolution Operator

Scope of the variable is the life time of the variable in the program.
A variable can either global or local scope.

Global Variable is a declared in the main body of the source code outside all functions while the local variable is the one declared within the body of function or block.

In 'C' the global version version of the variable of the variable can not be accessed from within the inner block.

In C++ , scope resolution operator (::) is used to access global variable.
Syntax:   ::global_variable_name;

#include<conio.h>
#include<iostream.h>
int a = 10;
void main( )
{
int a = 15;
clrscr( );
cout<<"\n\n\t Local a is -->"<<a<<"\tGlobal a is -->"<<::a;
a = 20;
cout<<"\n\n\t Local a is -->"<<a<<"\tGlobal a is -->"<<::a;
getch( );
}

OutPut:-
Local a is -->15     Global a is -->10
Local a is -->20     Global a is -->10

Output and Input Operator

cout <<"Welcome to the Computer Language";

This causes the string in quotation marks to be displayed on screen.

'cout' is a predefined object that represents standard output stream i.e. screen.

The operator '<<' is called as insertion or put to operator.It inserts the contents of the variable on its right to the object on its left.

Input Operator :

 cin >> no;
It is an input statement and causes the programs to wait for the user to type in a number.The number keyed in is placed in the variable 'no'.

'cin' is predefined object that represents standard input stream i.e. keyboard.

The operator '>>' is know as extraction or get from operator.
 
It extracts or takes the value from the keyboard and assigns it to the variable on its right.

Bitwise Operators

In order to manipulate the data at the bit level, the bitwise operators are provided in Java. These operators are used for testing the bits as well as shifting them to left or right etc.

These can be applied to integer types only.That is, they can not be used along with float or double value.


All these operator except one's complement operator are binary operators. These  perform the given bitwise operation on the operands.

Accordingly, the result is obtained.Shift operators shift the binary equivalent bits of the operand to respective left or right position.

Increment and Decrement Operators

Like C and C++ , Java is also having the increment and decrement operators' i.e. ++ and --. Both  of these are unary operators.The operator + + adds 1 to the operand and - - subtract 1 from the operand.

They can be written in following from:
 x++  or x--
 ++x  or --x

Both forms of the ++ increment the value of variable by one i.e. x++ or ++x will be equivalent to x = x+1. As well as , x - - is equivalent to x = x - 1.

When the increment or decrement operator is used before variable,it is called as pre-increment or post-increment operator.And when it is used after variable.it is called as post-increment or post-decrement operator.

The difference is simple.That is, when these pre-increment or pre-decrement operators are involved in the arithmetic expression .
For example,
 z = 14;
 y = z ++;

Here, the value of variable y will be 14 and z will be 15, because in the second expression, post increment operator is used. Value of variable z is assigned to y first and then it is incremented.If we change the second expression to,
y = ++z;

Now, both the values of y and z will be 15.Pre-increment operator does its job first the then uses the value in the expression.
 

Assignment Operators

Assignment operators are used to assign the value of an expression to the variable.The general assignment operator is '='. This is used to assign the value given to its right side to the variable written on left side.

Other assignment operators are also known as shorthand operators become they minimize our work of writing arithmetic expression.

Assignment operators are listed in table given below-

Popular Posts

Categories

AI (27) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (118) C (77) C# (12) C++ (82) Course (62) Coursera (180) Cybersecurity (22) data management (11) Data Science (95) Data Strucures (6) Deep Learning (9) Django (6) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flutter (1) FPL (17) Google (19) Hadoop (3) HTML&CSS (46) IBM (25) IoT (1) IS (25) Java (92) Leet Code (4) Machine Learning (44) Meta (18) MICHIGAN (5) microsoft (4) Pandas (3) PHP (20) Projects (29) Python (753) Python Coding Challenge (232) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (40) UX Research (1) web application (8)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses