Biyani's Think Tank Concept based notes
Principal of Programming Language (B.Tech )
Amrish Sharma Deepti Gupta
Asst. Professor Deptt. of Engineering Biyani International Institute of Engineering and Technology
For free study notes log on: www.gurukpo.com
2 Published by :
Think Tanks Biyani Group of Colleges
Concept & Copyright :
Biyani Shikshan Samiti Sector-3, Vidhyadhar Nagar, Jaipur-302 023 (Rajasthan) Ph : 0141-2338371, 2338591-95 Fax : 0141-2338007 E-mail :
[email protected] Website :www.gurukpo.com; www.biyanicolleges.org
Edition : 2013
While every effort is taken to avoid errors or omissions in this Publication, any mistake or omission that may have crept in is not intentional. It may be taken note of that neither the publisher nor the author will be responsible for any damage or loss of any kind arising to anyone in any manner on account of such errors and omissions.
Leaser Type Setted by: Biyani College Printing Department
For free study notes log on: www.gurukpo.com
PPL
3
Preface
I
am glad to present this book, especially designed to serve the needs of the students. The
book has been written keeping in mind the general weakness in understanding the fundamental concepts of the topics. The book is self-explanatory and adopts the “Teach Yourself” style. It is based on question-answer pattern. The language of book is quite easy and understandable based on scientific approach. Any further improvement in the contents of the book by making corrections, omission and inclusion is keen to be achieved based on suggestions from the readers for which the author shall be obliged. I acknowledge special thanks to Mr. Rajeev Biyani, Chairman & Dr. Sanjay Biyani, Director (Acad.) Biyani Group of Colleges, who are the backbones and main concept provider and also have been constant source of motivation throughout this Endeavour. They played an active role in coordinating the various stages of this Endeavour and spearheaded the publishing work. I look forward to receiving valuable suggestions from professors of various educational institutions, other faculty members and students for improvement of the quality of the book. The reader may feel free to send in their comments and suggestions to the under mentioned address.
For free study notes log on: www.gurukpo.com
4
Syllabus
For free study notes log on: www.gurukpo.com
Unit I
Programming Language Overview Q.1
What do you understand by programming language ?
Ans
An artificial language used to write instructions that can be translated into machine language and then executed by a computer.
Q.2
Explain the features of programming language ?
Ans 1 . Low Level Features : 1. C Programming provides low level features that are generally provided by the Lower level languages. C is Closely Related to Lower level Language such as “Assembly Language“. 2. It is easier to write assembly language codes in C programming. 2 . Portability : 1. Programs are portable i.e they can be run on any Compiler with Little or no Modification 2. Compiler and Preprocessor make it Possible for Program to run it on Different PC 3 . Powerful 1. Provides Wide verity of „Data Types„ 2. Provides Wide verity of „Functions‟ 3. Provides useful Control & Loop Control Statements 4 . Bit Manipulation 1. C Programs can be manipulated using bits. We can perform different operations at bit level. We can manage memry representation at bit level. 2. It provides wide verity of bit manipulation Operators. We have bitwise operators to manage Data at bit level. 5 . High Level Features :
For free study notes log on: www.gurukpo.com
6
1. It is more User friendly as compare to Previous languages. Previous languages such as BCPL,Pascal and other programming languages never provide such great features to manage data. 2. Previous languages have there pros and cons but C Programming collected all useful features of previous languages thus C become more effective language. 6 . Modular Programming 1. Modular programming is a software design technique that increases the extent to which software is composed of separate parts, called modules 2. C Program Consist of Different Modules that are integrated together to form complete program 7 . Efficient Use of Pointers 1. Pointers has direct access to memory. 2. C Supports efficient use of pointer . Q.3
What are the programming paradigms ?
Ans
A way of conceptualizing what it means to perform computation and how tasks to be carried out on the computer should be structured and organized. » » » »
Imperative : Machine-model based Functional : Equations; Expression Evaluation Logical : First-order Logic Deduction Object-Oriented : Programming with Data Types
Imperative Imperative programs tells the details of HOW the results are to be obtained, in terms of the underlying machine model. It contains both the specification and the implementation details, inseparably inter-twined. Imperative Style i := 0; sum := 0; while (i < n) do i := i + 1; sum := sum + i end; For free study notes log on: www.gurukpo.com
–
Storage efficient
Functional 1) 2) 3) 4)
Program: a collection of function definitions (m/c independent). Computation by term rewriting. Recursion. Assign-only-once variables. Functional Style
–
func sum(i:int) : int; if i = 0 then 0 else i + sum(i-1) end; No Side-effect
Logic Programming Integrates Data and Control Structures edge(a,b). edge(a,c). edge(c,a). path(X,X). path(X,Y) :- edge(X,Y). path(X,Y) :- edge(X,Z), path(Z,Y).
Declarative Programming A logic program defines a set of relations. This “knowledge” can be used in various ways by the interpreter to solve different queries. Q.4
What is the difference between procedural and object-oriented programming ? For free study notes log on: www.gurukpo.com
8
Ans Procedural 1) Emphasis on procedural abstraction.
Object-Oriented 1) Emphasis on data abstraction.
2) Top-down design.
2) Bottom-up design
3) Step-wise refinement. 4) Suited for programming in the small.
3)Reusable libraries. 4) Suited for programming in the large.
Q.5
Explain the structure of computer ?
Ans
A computer consists of three main parts: 1) Processor (CPU) 2) Main-memory system 3) I/O system The CPU consists of a control unit, registers, the arithmetic and logic unit, the instruction execution unit, and the interconnections among these components. The information handled by a computer. Instruction Govern the transfer information within a computer as well as between the computer and its I/O devices Specify the arithmetic and logic operations to be performed Data Numbers and encoded characters that are used as operands by the instructions. ALU Most computer operations are performed in the arithmetic and logic unit (ALU) of the processor For example, consider two numbers stored in the memory are to be added They are brought into the processor, and the actual addition is carried out by the ALU. Then sum may be stored in the memory or retained in the processor for immediate use. Typical arithmetic and logic operation are 1) Addition, 2) subtraction 3) multiplication 4) division
For free study notes log on: www.gurukpo.com
5) comparison, 6) complement, etc. When operands are brought into the processor, they are stored in high-speed storage elements called registers. Each register can store one word of data. Control Unit The control unit is the nerve center that sends control signals to other units and senses their states.Thus the control unit serves as a coordinator of the memory, arithmetic and logic, and input/output units. The operation of a computer can be summarized as follows: The computer accepts information in the form of programs and data through an input unit and stores it in the memory. Information stored in the memory is fetched, under program control, into an ALU, where it is processed Processed information leaves the computer through an output unit. All activities inside the machine are directed by the control unit.
Q.6
What are the operations of computer ?
For free study notes log on: www.gurukpo.com
10
Ans
Computer system can do various works but some important among them are:1) 2) 3) 4) 5) 6)
Q.7
I/O devices and the CPU can execute concurrently. Each device controller is in charge of a particular device type. Each device controller has a local buffer. CPU moves data from/to main memory to/from local buffers I/O is from the device to local buffer of controller. Device controller informs CPU that it has finished its operation by causing an interrupt.
Give the history of programming language ?
Ans
For free study notes log on: www.gurukpo.com
Q.8
What do you mean by syntax in programming language?
Ans
Syntax refers to the ways symbols may be combined to create well-formed sentences (or programs) in the language. Syntax defines the formal relations between the constituents of a language, thereby providing a structural description of the various expressions that make up legal strings in the language. Syntax deals solely with the form and structure of symbols in a language without any consideration given to their meaning.
Q.9
What do you mean by semantics in programming language ?
For free study notes log on: www.gurukpo.com
12
Ans
Semantics reveals the meaning of syntactically valid strings in a language. For natural languages, this means correlating sentences and phrases with the objects, thoughts, and feelings of our experiences. For programming languages, semantics describes the behavior that a computer follows when executing a program in the language. We might disclose this behavior by describing the relationship between the input and output of a program or by a step-by-step explanation of how a program will execute on a real or an abstract machine.
For free study notes log on: www.gurukpo.com
Unit II
Implementation of Elementary & Structured Data Types
Q.1
Explain the concept of Array ?
Ans
A Arrays is a collection of homogenous data elements (data types) describing by single name. Arrays is three types:1) One-dimensional Arrays 2) 2 dimensional Arrays 3) Multi-dimensional Array The basic purpose of using Arrays is short the programming and similarly using data in a single program. One-D Array:- A list of items can be given a common name and the individual items can be referred using only one sub script. Declaration:Syntax:- Type array name [Array size]; Ex:- int a [5]; Or Int a [5] = {2, 4, 5, 6, 7} Int a [ ]; Double – range 2.22507 e-308 to 1.797669 e+308 Long double; 2.22507 e+308 Accessing Element of array. The C language using single index to access individual element in a one dimensional array Ex:int marks [10] for (i=0; I and