0% found this document useful (0 votes)
92 views

C Language

C is considered a middle-level language because it provides some high-level features like functions and modularity, but also allows for low-level programming and direct access to memory through pointers. It is efficient for developing both applications and operating systems. Learning C helps build an understanding of how computer systems work at a basic level, which can improve programming ability in other languages. C was one of the earliest widely used professional languages and remains very common due to its flexibility and performance.

Uploaded by

danny cool
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

C Language

C is considered a middle-level language because it provides some high-level features like functions and modularity, but also allows for low-level programming and direct access to memory through pointers. It is efficient for developing both applications and operating systems. Learning C helps build an understanding of how computer systems work at a basic level, which can improve programming ability in other languages. C was one of the earliest widely used professional languages and remains very common due to its flexibility and performance.

Uploaded by

danny cool
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Q

Auest. Why learning “C” is important?

ns. The importance of C language is that the time efficiency of C programs are very high
compared to others. Moreover it is a middle level language. i.e. You can write a C program that
can perform the task of a program written in low level language as well as the program written in
high level language.
We briefly list some of C's characteristics that define the language and also have lead to its
popularity as a programming language. Naturally we will be studying many of these aspects
throughout the course.

 Small size
 Extensive use of function calls
 Loose typing - unlike PASCAL
 Structured language
 Low level (Bitwise) programming readily available
 Pointer implementation - extensive use of pointers for memory, array, structures and
functions.

C has now become a widely used professional language for various reasons.

 It has high-level constructs.


 It can handle low-level activities.
 It produces efficient programs.
 It can be compiled on a variety of computers.

Its main drawback is that it has poor error detection which can make it off putting to the
beginner. However diligence in this matter can pay off handsomely since having learned the
rules of C we can break them. Not many languages allow this. This if done properly and
carefully leads to the power of C programming.

The standard for C programs was originally the features set by Brian Kernighan. In order to
make the language more internationally acceptable, an international standard was developed,
ANSI C (American National Standards Institute).
Q uest. Difference between “C” and C++?

A ns. C does not have any classes or objects. It is procedure and function driven. There is no
concept of access through objects and structures are the only place where there is a access
through a compacted variable. c++ is object oriented.

 C structures have a different behaviour compared to c++ structures. Structures in c do not


accept functions as their parts.

 C input/output is based on library and the processes are carried out by including
functions. C++ i/o is made through console commands cin and cout.

 C functions do not support overloading. Operator overloading is a process in which the


same function has two or more different behaviours based on the data input by the user.

 C does not support new or delete commands. The memory operations to free or allocate
memory in c are carried out by malloc() and free().

 Undeclared functions in c++ are not allowed. The function has to have a prototype
defined before the main() before use in c++ although in c the functions can be declared at
the point of use.

 After declaring structures and enumerators in c we cannot declare the variable for the
structure right after the end of the structure as in c++.

 For an int main() in c++ we may not write a return statement but the return is mandatory
in c if we are using int main().

 In C++ identifiers are not allowed to contain two or more consecutive underscores in any
position. C identifiers cannot start with two or more consecutive underscores, but may
contain them in other positions.

 C has a top down approach whereas c++ has a bottom up approach.

 In c a character constant is automatically elevated to an integer whereas in c++ this is not


the case.

 In c declaring the global variable several times is allowed but this is not allowed in c++.

 c is procedure oriented programing & c++ is object


Q

Auest. What is object oriented programming language?

ns. Object-oriented programming (OOP) is a programming language model organized around


"objects" rather than "actions" and data rather than logic. Historically, a program has been
viewed as a logical procedure that takes input data, processes it, and produces output data.

The programming challenge was seen as how to write the logic, not how to define the data.
Object-oriented programming takes the view that what we really care about are the objects we
want to manipulate rather than the logic required to manipulate them. Examples of objects range
from human beings (described by name, address, and so forth) to buildings and floors (whose
properties can be described and managed) down to the little widgets on your computer desktop
(such as buttons and scroll bars).

The first step in OOP is to identify all the objects you want to manipulate and how they relate to
each other, an exercise often known as data modeling. Once you've identified an object, you
generalize it as a class of objects (think of Plato's concept of the "ideal" chair that stands for all
chairs) and define the kind of data it contains and any logic sequences that can manipulate it.
Each distinct logic sequence is known as a method. A real instance of a class is called (no
surprise here) an "object" or, in some environments, an "instance of a class." The object or class
instance is what you run in the computer. Its methods provide computer instructions and the class
object characteristics provide relevant data. You communicate with objects - and they
communicate with each other - with well-defined interfaces called messages.

The concepts and rules used in object-oriented programming provide these important benefits:

 The concept of a data class makes it possible to define subclasses of data objects that share
some or all of the main class characteristics. Called inheritance, this property of OOP forces a
more thorough data analysis, reduces development time, and ensures more accurate coding.
 Since a class defines only the data it needs to be concerned with, when an instance of that class
(an object) is run, the code will not be able to accidentally access other program data. This
characteristic of data hiding provides greater system security and avoids unintended data
corruption.
 The definition of a class is reuseable not only by the program for which it is initially created but
also by other object-oriented programs (and, for this reason, can be more easily distributed for
use in networks).
 The concept of data classes allows a programmer to create any new data type that is not already
defined in the language itself.

Simula was the first object-oriented programming language. Java, Python, C++, Visual Basic
.NET and Ruby are the most popular OOP languages today. The Java programming language is
designed especially for use in distributed applications on corporate networks and the Internet.
Ruby is used in many Web applications. Curl, Smalltalk, Delphi and Eiffel are also examples of
object-oriented programming languages.
Q

Auest. What is Non-Procedural language?

ns. A computer language that does not require writing traditional programming logic. Also
known as a "declarative language," users concentrate on defining the input and output rather than
the program steps required in a procedural language such as C++ or Java. For example, a
command, such as LIST, might display all the records in a file on screen, separating fields with a
blank space. In a procedural language, all the logic for inputting each record, testing for end of
file and formatting each column on screen has to be explicitly programmed.

Query languages, report writers, interactive database programs, spreadsheets and application
generators are examples of non-procedural languages. Contrast with procedural language.

The following dBASE examples show procedural and non-procedural ways to list a file.
Procedural and non-procedural languages are also considered third and fourth-generation
languages (3GL and 4GL).

Auest. Why C is treated middle level language?

ns. C is a language that can be used to develop both 'user applications' and 'operating systems'. It
allows you to have access to the machine language itself if you so choose (inline asm). Most of
the unix operating system is written in C. It is a great language to start with (IMHO) because it
contains the basic concepts of computer programming. As well as giving you a feel for what
actually goes on in the machine itself. Higher level languages abstract you from the machine,
usually (again IMHO) focusing more on the rapid development of Applications. Remembering
that C++ was originally developed as C with classes, learning C is (again IMHO) almost a pre-
requisite for learning C++.
I have found over the years that my understanding of the machine that I gained writing C has
helped me immensely in designing more efficient applications in, say, VB.NET and other
languages of it's ilk, as well as repairing the occasional bug that might appear in my High Level
language code.

C Programming language is called as Middle Level Language because

(i) It gives or behaves as High Level Language through Functions - gives a modular programming and
breakup, increased efficiency for reusability

(ii) it gives access to the low level memory through Pointers. Moreover it does support the Low Level
programming i.e, Assembly Language.
Q

Auest. Difference between Flow Chart and Pseudo Code?

ns. Flowcharts and pseudocode provide ways for computer programmers and others working on
a project to have an upper-level understanding of both the entire project and any algorithms
involved in it. Both flowcharts and pseudocode have benefits in describing the logic of the
algorithms and can be used at different points in the programming process. However, either of
these methods of planning for a project can save time and ensure everyone is on the same page.

Layout

The layout of flowcharts for a program provides a graphical structure that allows programmers to
follow the logical structure of the code. The graphical nature of the flowchart provides another
way to look at the sequence of the program, which can be especially beneficial for
nonprogramming members of the team who need to understand how the code will work. The
layout of pseudocode follows more closely the structure for the code of the program. Pseudocode
uses words as opposed to a pictorial representation to illustrate the logic of the algorithm.

Benefits

Flowcharts are especially beneficial for smaller concepts and problems, while pseudocode is
more efficient for larger programming problems. Flowcharts provide an easy method of
communication about the logic and offer a good starting point for the project because they are
easier to create than pseudocode in the beginning stages. Pseudocode provides a beneficial
bridge to the project code because it closely follows the logic that the code will. Pseudocode also
helps programmers share ideas without spending too much time creating code, and it provides a
structure that is not dependent on any one programming language.

Structure

The structure of pseudocode uses a linear text-based structure to organize the logic of the
programming problem. It does not need so much detail as to include variables and function
names but should include enough detail so that code can be created to follow the same logic. The
structure of flowcharts uses symbols and shapes to create a diagram of only the essential parts of
the algorithm or problem. While it is sometime not enough to begin coding from, especially for
larger systems, it can provide a broad idea of how the system will function.

Depth

Both pseudocode and flowcharts can be either broad and cover only basic concepts of the
algorithm or project, or they can cover more detail, making the jump to creating the codes easier.
However, pseudocode has more flexibility with detail; too much detail in a flowchart can cause
confusion.
Q

Auest. What is Flow Chart? Why it is required in C and other language?

ns. Flow chart is a graphical representation of algorithm. It is used to represent algorithm steps into
graphical format. It also gives us an idea to organize the sequence of steps or events necessary to solve a
problem with the computer. In other words flow charts are symbolic diagrams of operations and the
sequence, data flow, control flow and processing logic in information processing. These charts are used
to understand any working sequence of the program.

Advantages of flowchart:-

1. It provides an easy way of communication because any other person besides the programmer can
understand the way they are represented.
2. It represents the data flow.
3. It provides a clear overview of the entire program and problem and solution.
4. It checks the accuracy in logic flow.
5. It documents the steps followed in an algorithm.
6. It provides the facility for coding.
7. It provides the way of modification of running program.
8. They show all major elements and their relationship.

Terminator
This symbol represents the beginning and end point in a program. We use start and stop option in it.

Input/Output Symbol
This symbol is used to take any input or output in the algorithm.

Process Symbol
A rectangle indicates the processing, calculation and arithmetic operations

Decision Symbol
It is used when we want to take any decision in the program.

Connector Symbol
This symbol is used to connect the various portion of a flow chart. This is normally used when the flow
chart is split between two pages

Data Flow Symbol


This symbol is used to display the flow of the program. It shows the path of logic flow in a program.
Q

Auest. Difference between Run-time error and Compile-time error?

ns. At compile time, when the code does not comply with the Java syntactic and semantics rules
as described in Java Language Specification (JLS), compile-time errors will occurs. The goal of
the compiler is to ensure the code is compliant with these rules. Any rule-violations detected at
this stage are reported as compilation errors.

The best way to get to know those rules is to go through all the sections in the JLS containing the
key words "compile-time error". In general, these rules include syntax checking: declarations,
expressions, lexical parsing, file-naming conventions etc; exception handling: for checked
exceptions; accessibility, type-compatibility, name resolution: checking to see all named entities
- variables, classes, method calls etc. are reachable through at least one of the declared path; etc.

The following are some common compile time errors:

 a class tries to extend more than one class


 overloading or overriding is not implemented correctly
 attempt to refer to a variable that is not in the scope of the current block
 an inner class has the same name as one of one of its enclosing classes
 a class contains one or more abstract methods and the class itself is not declared "abstract"
 a class tries to reference a private member of another class
 trying to create an instance of an abstract class
 trying to change the value of an already initialized constant (final member)
 declare two (class or instance) members with the same name

Here is a list of conditions that may cause compile-time errors. 

When the code compiles without any error, there is still chance that the code will fail at run time.
The errors only occurs at run time are call run time errors. Run time errors are those that passed
compiler's checking, but fails when the code gets executed. There are a lot of causes may result
in runtime errors, such as incompatible type-casting, referencing an invalid index in an array,
using an null-object, resource problems like unavailable file-handles, out of memory situations,
thread dead-locks, infinite loops(not detected!), etc.

The following are some common runtime errors:

 trying to invoke a method on an uninitialized variable (NullPointerException)


 ran out memory (memory leaks...) (OutOfMemoryError)
 trying to open a file that doesn't exist (FileNotFoundException)
 trying to pass arguments to a method which are not within the accepted bounds
(IllegalArgumentException)
 trying to invoke the start() method on a dead thread (IllegalThreadStateException)
 trying to invoke wait() or notify() on an object without owning the object's monitor
(IllegalMonitorStateException)
Q

Auest. Why Bitwise operators are used in C language ?

ns. Bitwise operators interpret operands as strings of bits. Bit operations are performed on this data to
get the bit strings. These bit strings are then interpreted according to data type. There are six bit
operators: bitwise AND(&), bitwise OR(|), bitwise XOR(^), bitwise complement(~), left shift(<<), and right
shift(>>). We use bitwise operators in some programming contexts because bitwise operations are faster
than (+) and (-) operations and significantly faster than (*) and (/) operations. Here is a program which
demonstrate C bitwise operator:

Uses of Bitwise Operations


Occasionally, you may want to implement a large number of Boolean variables, without using a lot of
space.

A 32-bit int can be used to stored 32 Boolean variables. Normally, the minimum size for one
Boolean variable is one byte. All types in C must have sizes that are multiples of bytes.
However, only one bit is necessary to represent a Boolean value.

You can also use bits to represent elements of a (small) set. If a bit is 1, then element i is in the
set, otherwise it's not.

You can use bitwise AND to implement set intersection, bitwise OR to implement set union.

In upcoming notes, you'll learn how to find the value of individual bits of a char or int.

Facts About Bitwise Operators


Consider the expression x + y. Do either x or y get modified? The answer is no.

Most built-in binary operators do not modify the values of the arguments. This applies to logical
operators too. They don't modify their arguments.

There are operators that do assignment such as +=, -=, *=, and so on. They apply to logical
operators too. For example, |=, &=, ^=. Nearly all binary operators have a version with = after it.

Summary

Bitwise operators only work on limited types: int and char (and variations of int). You can, with some
casting, make it work on other types. These operators, in conjunction with bitshift operators allow you
to access and modify bits.

You might also like