Tuesday, 23 December 2014

errors and types of errors

TYPES OF ERRORS:

Syntax Errors

When the rules of the c programming language are not followed, the compiler will show syntax errors.
For example, consider the statement,
1
int a,b:
The above statement will produce syntax error as the statement is terminated with : rather than ;

Semantic Errors

Semantic errors are reported by the compiler when the statements written in the c program are not meaningful to the compiler.
For example, consider the statement,
1
b+c=a;
In the above statement we are trying to assign value of a in the value obtained by summation of b and c which has no meaning in c. The correct statement will be
1
a=b+c;

Logical Errors

Logical errors are the errors in the output of the program. The presence of logical errors leads to undesired or incorrect output and are caused due to error in the logic applied in the program to produce the desired output.
Also, logical errors could not be detected by the compiler, and thus, programmers has to check the entire coding of a c program line by line

array

ARRAY:
C programming language provides a data structure called the array, which can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.
Instead of declaring individual variables, such as number0, number1, ..., and number99, you declare one array variable such as numbers and use numbers[0], numbers[1], and ..., numbers[99] to represent individual variables. A specific element in an array is accessed by an index.

All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.

function and its types

FUNCTION:

A function is a group of statements that together perform a task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions.

Types of function

  1. Function with no arguments and no return value
  2. Function with no arguments and return value
  3. Function with arguments but no return value
  4. Function with arguments and return value.


difference between while and do while loop

DIFFERENCES BETWEEN WHILE AND DO-WHILE LOOP:
1.       In While loop the condition is
tested first and then the statements are executed if the condition turns out to
be true.
In do while the statements are executed for the first time and then the conditions
are tested, if the condition turns out to be true then the statements are
executed again.

2. A do while is used for a block
of code that must be executed at least once.
These situations tend to be relatively rare, thus the simple while is more commonly
used.
    3. A do while loop runs at least once
     even though the the condition given is false
     while loop do not run in case the condition given is false



     4. In a while loop the condition is
    first tested and if it returns true then it goes in the loop
                     In a do-while loop the condition is
                      tested at the last.



5. While loop is entry control loop
where as do while is exit control loop.



6. Syntax:

 while loop  :
while (condition)
{
Statements;
}
do while loop  :
Do
{
Statements;
}while(condition)

The do while loop executes the content of the loop once before checking the condition of the while. Whereas a while loop will check the condition first before executing the content.
The while loop checks whether the  test expression is true or not. If it is true, code/s inside the body of while loop is executed,that is, code/s inside the braces { } are executed. Then again the test expression is checked whether test expression is true or not. This process continues until the test expression becomes false.

In C, do...while loop is very similar to while loop. Only difference between these two loops is that, in while loops, test expression is checked at first but, in do...while loop code is executed at first then the condition is checked. So, the code are executed at least once in do...while 

difference between C language and C++

Following are the differences Between C and C++ :


                               C
                              C++
1. C is Procedural Language.
1. C++ is non Procedural i.e Object oriented Language.
2. No virtual Functions are present in C
2. The concept of virtual Functions are used in C++.
3. In C, Polymorphism is not possible.
3. The concept of polymorphism is used in C++.
Polymorphism is the most Important Feature of OOPS.
4. Operator overloading is not possible in C.
4. Operator overloading is one of the greatest Feature of C++.
5. Top down approach is used in Program Design.
5. Bottom up approach adopted in Program Design.
6. No namespace Feature is present in C Language.
6. Namespace Feature is present in C++ for avoiding Name collision.
7. Multiple Declaration of global variables are allowed.
7. Multiple Declaration of global varioables are not allowed.
8. In C
  • scanf() Function used for Input.
  • printf() Function used for output.
8. In C++
  • Cin>> Function used for Input.
  • Cout<< Function used for output.
9. Mapping between Data and Function is difficult and complicated.
9. Mapping between Data and Function can be used using "Objects"
10. In C, we can call main() Function through other Functions
10. In C++, we cannot call main() Function through other functions.
11. C requires all the variables to be defined at the starting of a scope.
11. C++ allows the declaration of variable anywhere in the scope i.e at time of its First use.
12. No inheritance is possible in C.
12. Inheritance is possible in C++
13. In C, malloc() and calloc() Functions are used for Memory Allocation and free() function for memory Deallocating.
13.In C++,  new and delete operators are used for Memory Allocating and Deallocating.
14. It supports built-in and primitive data types.
14. It support both built-in and user define data types.

switch case

SWITCH CASE:

A 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.

loop

LOOP:


In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached. Typically, a certain process is done, such as getting an item of data and changing it, and then some condition is checked such as whether a counter has reached a prescribed number. If it hasn't, the next instruction in the sequence is an instruction to return to the first instruction in the sequence and repeat the sequence. If the condition has been reached, the next instruction "falls through" to the next sequential instruction or branches outside the loop. A loop is a fundamental programming idea that is commonly used in writing programs.

structured programming

STRUCTURED PROGRAMMING

Structured programming, sometimes known as modular programming, is a subset of procedural programming that enforces a logical structure on the program being written to make it more efficient and easier to understand and modify. Orrrr To many people, Edsger W. Dijkstra's letter to the Editor of Communications of the ACM, published in March 1968, marks the true beginning of structured programming. Structured programming can be seen as a subset or subdiscipline of imperative programming, one of the major programming paradigms. It is most famous for removing or reducing reliance on the GOTO statement. Edsger Dijkstra's subsequent article, "Go To Statement Considered Harmful" was instrumental in the trend towards structured programming. Description of the inverse relationship between a programmer's ability and the density of goto statements in his program is repeated.[1]

C language

C Programming Language
C is a high-level and general purpose programming language that is ideal for developing firmware or portable applications. Originally intended for writing system software, C was developed at Bell Labs by Dennis Ritchie for the Unix Operating System (OS) in the early 1970s.

Ranked among the most widely used languages, C has a compiler for most computer systems and influenced many popular languages - notably C++.