PPS
Unit – 1Introduction To Programming Q1.Explain the following terms:Memory Disks Operating systems Compilers A1. Memory: A memory is used to store data and instructions. Computer memory is the storage space in the computer, where data is to be processed and instructions required for processing are stored. The memory is divided into large number of small parts called cells. Each location or cell has a unique address, which varies from zero to memory size minus one. For example, if the computer has 64k words, then this memory unit has 64 * 1024 = 65536 memory locations. The address of these locations varies from 0 to 65535.Memory is primarily of three types −Cache Memory Primary Memory/Main Memory Secondary Memory Cache MemoryCache memory is a high -speed semiconductor memory which can speed up the CPU. It acts as a buffer between the CPU and the main memory. It is used to hold those parts of data and program which are most frequently used by the CPU. The parts of data and programs are transferred from the disk to cache memory by the operating system, from where the CPU can access them.AdvantagesThe advantages of cache memory are as follows −Cache memory is faster than main memory. It consumes less access time as compared to main memory. It stores the program that can be executed within a short period of time. It stores data for temporary use. DisadvantagesThe disadvantages of cache memory are as follows −Cache memory has limited capacity. It is too expensive. Primary Memory (Main Memory)Primary memory holds only those data and instructions on which the computer is currently working. It has a limited capacity and data is lost when power is switched off. It is generally made up of semiconductor device. These memories are not as fast as registers. The data and instruction required to be processed resides in the main memory. It is divided into two subcategories RAM and ROM.Characteristics of Main MemoryThese are semiconductor memories. It is known as the main memory. Usually volatile memory. Data is lost in case power is switched off. It is the working memory of the computer. Faster than secondary memories. A computer cannot run without the primary memory. Secondary MemoryThis type of memory is also known as external memory or non-volatile. It is slower than the main memory. These are used for storing data/information permanently. CPU directly does not access these memories, instead they are accessed via input-output routines. The contents of secondary memories are first transferred to the main memory, and then the CPU can access it. For example, disk, CD-ROM, DVD, etc.Characteristics of Secondary MemoryThese are magnetic and optical memories. It is known as the backup memory. It is a non-volatile memory. Data is permanently stored even if power is switched off. It is used for storage of data in a computer. Computer may run without the secondary memory. Slower than primary memories. Disks:Generally, a disk is a round plate on which data can be encoded. There are two basic types of disks: magnetic disks and optical disks.Operating systemsWhenever you save your program (anything) into a file (any kind of file, say ‘add.c’), it automatically gets stored in the secondary storage that is the hard disk. The Operating System’s kernel (kernel’s File management system) does it for you.When you run program, it is loaded into the main/primary memory of the computer called RAM (the entire program is transferred to the RAM, by a small program called the loader (which often comes with the compiler i.e. is a part of the compiler).The program instructions are executed in the ALU (Arithmetic-Logic Unit) of the CPU (in its registers like the Accumulator). In order to execute the instructions , the CPU fetches the values of the variables (say, int a =10; int b =20;) in the program from the RAM, and stores the results also in the RAM (int sum =30;), which is then sent to the output buffer stream (stdout) , which prints the results (30) on the computer console/terminal, the Windows kernel (kernel’s I/O management system) does the printing . Compiler
Compiler is a program that translates source code into object code. The compiler derives its name from the way it works, looking at the entire piece of source code and collecting and reorganizing the instructions. Thus, a compiler differs from an interpreter, which analyses and executes each line of source code in succession, without looking at the entire program. The advantage of interpreters is that they can execute a program immediately. Compilers require some time before an executable program emerges. However, programs produced by compilers run much faster than the same programs executed by an interpreter.Every high- level programming language comes with a compiler. In effect, the compiler is the because it defines which instructions are acceptable.Because compilers translate source code into object code, which is unique for each type of computer many compilers are available for the same language. Q2.Describe algorithm and the steps involved to solve a problem to achieve the task.A2. An algorithm is the finite set of English statements which are designed to accomplish the specific task. Study of any algorithm is based on the following four criteria1. Design of algorithm:This is the first step in the creation of an algorithm. Design of algorithm includes the problem statement which tell user about the area for which algorithm is required. After problem statement next important thing required is the information about available and required resources. The last thing required in design of algorithm phase is information about the expected output.2. Validation of algorithm: Once an algorithm is designed , it is necessary to validate it for several possible input and make sure that algorithm is providing correct output for every input. This process is known as algorithm validation. The purpose of the validation is to assure us that this algorithm will work correctly independently of the issues concerning the programming language it will eventually be written in. 3. Analysis of algorithm: Analysis of algorithms is also called as performance analysis. This phase refers to the task of determining how much computing time and storage an algorithm requires. The efficiency is measured in best case, worst case and average case analysis.4. Testing of algorithm:This phase is about to testing of a program which coded as per the algorithm. Testing of such program consists of two phases: Debugging: It is the process of executing programs on sample data sets to determine whether faulty results occur or not and if occur, to correct them. Profiling : Profiling or performance measurement is the process of executing a correct program on data sets and measuring the time and space it takes to compute the result.Q3. Explain the characteristics and uses of algorithm.A3. Characteristics of an algorithm Input: Algorithm must accept zero or more inputs. Output: Algorithm must provide at least one quantity. Definiteness: Algorithm must consist of clear and unambiguous instruction. Finiteness: Algorithm must contain finite set of instruction and algorithm will terminates after a finite number of steps. Effectiveness: Every instruction in algorithm must be very basic and effective.Uses of algorithm Algorithm provide independent layout of the program. It is easy to develop the program in any desired language with help of layout. Algorithm representation is very easy to understand. To design algorithm there is no need of expertise in programming language. Q4. Write a short note on the representation of algorithm.A4. There are three ways to represent an algorithm. Consider the following algorithm of addition of two numbersStep 1 : Start Step 2 :Read a number, say x and yStep 3 :Add x and y Step 4 :Display AdditionStep 5 :Stop1. Flowcharts: A flow chart is a diagrammatic / pictorial representation of an algorithm. It is the simplest way of representation of algorithm. Initially an algorithm is represented in the form of flowchart and then flowchart is given to programmer to express it in some programming language. Logical error detection is very easy in flowchart as it shows the flow of operations in diagrammatic form. Once flowchart is ready it is very easy to write a program in terms of statements of a programming language. Following are the symbols used in designing the flowcharts.2. Pseudo code: Pseudo code is the combination of English statements with programming methodology. In pseudo code, there is no restriction of following the syntax of the programming language. Pseudo codes cannot be compiled. It is just a previous step of developing a code for given algorithm. 3. Program: In this way of representation, complete algorithm is represented using some programming language by following the complete syntax of programming language.
Q5. What is a variable? Explain data types?A5. Variables are the names you give to computer memory locations which are used to store values in a computer program.Here are the following three simple steps −Create variables with appropriate names. Store your values in those two variables. Retrieve and use the stored values from the variables. When creating a variable, we need to declare the data type it contains. Programming languages define data types differently. For example, almost all languages differentiate between ‘integers’ (or whole numbers, eg 12), ‘non-integers’ (numbers with decimals, eg 0.24), and ‘characters’ (letters of the alphabet or words).char – a single 16-bit Unicode character, such as a letter, decimal or punctuation symbol. boolean – can have only two possible values: true (1) or false (0). This data type is useful in conditional statements. byte - has a minimum value of -128 and a maximum value of 127 (inclusive). short– has a minimum value of -32,768 and a maximum value of 32,767 int: – has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). long – has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). float – a floating point number with 32-bits of precision double – this is a double precision floating point number. Q6. What is type casting?A6. Type casting refers to changing variable of one data type into another. The compiler will automatically change one type of data into another. For instance, if you assign an integer value to a floating-point variable, the compiler will convert the int to a float. Casting allows you to make this type conversion explicit, or to force it when it would not normally happen.Type conversion in c can be classified into the following two types:1. Implicit Type ConversionWhen the type conversion is performed automatically by the compiler without programmers intervention, such type of conversion is known as implicit type conversion or type promotion.int x;for(x=97; x<=122; x++){printf("%c", x); /*Implicit casting from int to char thanks to %c*/}2. Explicit Type ConversionThe type conversion performed by the programmer by posing the data type of the expression of specific type is known as explicit type conversion. The explicit type conversion is also known as type casting.Type casting in c is done in the following form:(data_type)expression;where, data_type is any valid c data type, and expression may be constant, variable or expression.For example,int x;for(x=97; x<=122; x++){printf("%c", (char)x); /*Explicit casting from int to char*/}The following rules need to be followed while converting the expression from one type to another to avoid the loss of information:All integer types to be converted to float. All float types to be converted to double. All character types to be converted to integer. ExampleConsider the following code:int x=7, y=5 ;float z;z=x/y; /*Here the value of z is 1*/If we want to get the exact value of 7/5 then we need explicit casting from int to float:int x=7, y=5;float z;z = (float)x/(float)y; /*Here the value of z is 1.4*/Q7. Explain RTE?A7. Stands for "Runtime Environment." As soon as a software program is executed, it is in a run time state. In this state, the program can send instructions to the computer's processor and access the computer's memory and other system resources.When software developers write programs, they need to test them in the runtime environment. Therefore, software development programs often include an RTE component that allows the programmer to test the program while it is running. This allows the program to be run in an environment where the programmer can track the instructions being processed by the program and debug any errors that may arise. If the program crashes, the RTE software keeps running and may provide important information about why the program crashed. Q8. Explain the types of storage classes?A8. A storage class is used to describe the following things:The variable scope. The location where the variable will be stored. The initialized value of a variable. A lifetime of a variable.
Q9. Explain the syntax and logical errors in compilation?A9. A syntax error is an error in the source code of a program. Since computer programs must follow strict syntax to compile correctly, any aspects of the code that do not conform to the syntax of the programming language will produce a syntax error. • Spelling mistakes • Missing out quotes • Missing out brackets • Using upper case characters in key words e.g. IF instead of if • Missing out a colon or semicolon at end of a statement • Using tokens in the wrong order A logic error (or logical error) is a ‘bug’ or mistake in a program’s source code that results in incorrect or unexpected behaviour. It is a type of runtime error that may simply produce the wrong output or may cause a program to crash while running.Q10. Explain object and executable code?A10.
Source code is the C program that you write in your editor and save with a ‘ .C ‘ extension which is un-compiled when written for the first time or whenever a change is made in it and saved.Object code is the output of a compiler after it processes the source code. The object code is usually a machine code, also called a machine language, which can be understood directly by a specific type of CPU. However, some compilers are designed to convert source code into an assembly language or some other another programming language. An assembly language is a human-readable notation using the mnemonics in the ISA of that particular CPU.Executable (also called the Binary) is the output of a linker after it processes the object code. A machine code file can be immediately executable, runnable as a program , or it might require linking with other object code files for example libraries to produce a complete executable program.
Sr. No. | Name of Symbol | Symbol | Meaning / Purpose |
1. | Terminal |
| To indicate START / STOP. Usually it is the first symbol and last symbol used in program logic. |
2. | Input / Output Statement | To indicate input / output of Data | |
3. | Processing Statement | To indicate the processing of instructions. | |
4. |
Decision Box |
| To indicate decision making and a branch to one or more alternatives. |
5. | Flow Lines | To indicate the direction of flow of information. | |
6. | Connector |
| It is used when flowchart becomes long and need to be continued. Shows the continuity of the algorithm on the next page. |
0 matching results found