You are on page 1of 14

QUESTIONS & ANSWERS

SUBJUCT:-COMPUTER CONCEPTS AND C PROGRAMMING

Unit-1
Q1. What is a computer? Ans:- A computer is an electronic device that accepts input data, produces the desired output. The main tasks that are carried out by any computer are 1.Accepting data. 2. Processes or manipulates the data by performing various mathematical operations. 3. Output the result in the form which is suitable for human understanding 4. Stores the input data and results. Q2. What is Hardware ? Ans:- The word hardware represents the physical components which make up the computer system. The generally available hardware components are keyboard, floppy drive, hard disk, monitor, mouse, memory, CPU, printer, modem, speakers, transistors, etc. Q3. What is software? Ans:- The word software represents the set of programs that are necessary for the proper functioning of the hardware units. The programs, which are nothing but the instructions, will instruct the computer to perform various arithmetic operations such as addition, subtraction etc., and logical operations and how these operations are performed. Q4. What are the functional units of a digital computer? Ans:- Logical organization of a digital computer A computer consists of five functionally independent main parts 1.Arithmetic and logic unit 2.Control unit 3.Memory 4.Input unit 5.out put unit Memory Input unit Out put unit

Control Unit

ALU

Q5. What is are high-level language? Ans:- High level language The difficulties associated with assembly languages high level or procedure oriented languages have been developed. Instructions in HLL is called as statements. Statements clearly resemble English and Mathematics. HLL is independent of a computer; same program will run on any computer which has a compiler. Easier and faster to write. Provide better documentation , and programs are portable. Q6. Differentiate between compiler and interpreter. Ans:- Compiler A program which translates a high-level language program into a machine language program is called a compiler. It is intelligent than assembler It checks all kinds of limits, ranges errors etc, Occupies a large part of the memory, low speed an low efficiency of memory utilization Interpreter It is a program which translates statements of a high level language program into machine code, It translates one statement of the program at a time. Compiler goes through the entire high level language once or twice and translates the entire program into machine codes. Q7. What is an operating system? Name some of the widely used operating systems? Ans:- Operating System: Controls the computer's use of its hardware resources such as memory and disk storage. o Examples include DOS, Windows95, OS/2, MacOS, Unix o Control Basic Input & Output (I/O) o Allocate System Resources (CPU, registers, memory) o Manage Storage Space (Disk space) o Maintain Security (Passwords, File protection) o Detect Equipment Failure (Disk Crash, Program error) DOS and Unix are command driven operating systems. Mac and MSWindows are GUIs that incorporate multitasking -running multiple programs at once, each in its own window.

Q8. What is Algorithms Ans:- Algorithm is a problem solving technique. It can be defined as a step by step procedure to solve a particular problem. It consists of English like statements. Each statement must be precise and well-defined to perform a specific operation. When these statements are carried out for a given set of conditions, they would produce the required results. Q9. What is a flowchart? Ans:- A flowchart is a visual or graphical representation of an algorithm. It indicates the process of solution. The relevant operations and computations, the point of decisions and other information as part of the solution. Flowcharts are constructed by using special geometrical symbols. Each symbol represents an activity. The activity could be input/output of data, computation/processing of data, taking a decision or terminating the solution etc. The symbols are joined by arrows to obtain a complete flowchart. Q10. Explain the symbolsused in flowchart.
Symbols used in flowcharts

TERMINAL The beginning, end or a point interruption in a program

INPUT /OUTPUT Input or output of Information / PROCESSING Represents calculations, processing. data manipulations or information

PREPARATION (LOOPING) An instruction or group of instructions which changes the program. DECISION Represents a comparison a question or a Decision that determines a alternative paths to be followed PREDEFINED PROCESS A group of operations not detailed in the particular set of flowcharts.

CONNECTOR An entry or an exit to another part of the program flowchart

FLOW DIRECTION The direction of processing or data flow.

Q11. What are the character set in C language. Ans:- Character Set : Letters : A..Z, a..z Digits : 0..9 Special characters : , . : ; ? ! | / \ ~ -_ $ % # & ^ * + - < > ( ) { } [ ] White space : blank space, horizontal tab, vertical tab, carriage return, new line, form feed. Q12. What are the various types of tokens available in C language. Ans:- C tokens in C language are. Keyword :- float, while, for, int,. Identifier:- main( ) , amount, sum, Constants :-13.5, 500, Strings :- ABC, MCA, Operators:- + - * % Special Symbols :- [ ] { }

Q13. What are the different data types available in C language? Ans:- The different Data Types in C are Primary data types User defined data type Derived data type (array, function, structure,..) Empty data set Q14. Briefly explain the basic structure of C program? Ans:- Basic Structure of a C program main() A pair of curly braces Declarations and statements User defined functions Name of program is main( ) Execution begins here

main( ) tells computer where program begins Only one main { - begin of function } end of function /* */ - comment : ignored by compiler. (5-marks)

Q15. what is the precedence among operators? Ans:- Precedence of Operators:


Highest priority to lowest priority ( ) [ ] -> . ! ~ ++ -- - (type) * & sizeof() */% + << >> < <= > >= == != & ^ | && || ?: += -= *= %= != &= <<= >>= , In case of &&, if 1st operand is zero the 2nd operand is not evaluated In case of || if the first operand is 1 the 2nd operand is not evaluated

Q16. what are the mathematical functions in c? (5-marks) Ans:- Mathematical functions C compiler support basic math functions like cos, sin, sqrt,.. #include<math.h> Functions log(x) , acos(x), asin(x), atan(x), cos(x), sin(x), log10(x), pow(x,y), sqrt(x), csoh(x), sinh(x), tann(x), ceil(x), floor(x), exp(x), fabs(x) , fmad(x,y) Redundant parenthesis do not cause errors or slow down the execution of an expression Use parenthesis to clarify the exact order of evaluation

Q17. What are logical operators? Ans:- Logical operators


&& (AND) || (OR) ! (NOT) && and || used when more than one condition is to be tested Evaluates to 0 or 1

Q18. Explain conditional operator.

Ans:

Conditional operator Ternary operator pair ? : exp1 ? exp2 : exp3 exp1 evaluated first , if true then exp2 is evaluated else exp3 is evaluated E.g., main() { int a,b ,x,y; a = 10; b = 20; x = (a>b) ? (a+b) : (b+5) ; /* x=25*/ y = (a<=b) ? (a+5) : (b+5) ; /* y=15*/ }

Q19. Explain bitwise operators. Ans:- Bitwise OperatorsUsed for Testing Setting Shifting Ist is used for char or int data types only Operations are applied to individual bits of the operand Same truth table as logical operators. Bitwise AND (&) Bitwise OR (| ) Bitwise NOT (~) Bitwise EXOR (^) E.g., x= 13 ; 0000 0000 0000 1101 y= 25; 0000 0000 0001 1001 x&y = 0000 0000 0000 1001 = 9 x | y = 0000 0000 0001 1101 = 29 x^ y = 0000 0000 0001 0100 = 20 ~x = 1111 1111 1111 0010 Bitwise left shift op << no_of bits_to_shift Bitwise right shift op >> no_of_bits_to_shift Q20. What is type conversion in expressions Ans:- Type conversion in Expressions If constants and variables are of mixed type they are converted to the same type Compiler converts all operands up to the type of the largest operand type promotion. All conversions are done operation by operation.

The final result converted to the operand on the left of the assignment operator During final assignment if Float is assigned to int : truncation of fractional part Double to float : causes rounding off of digits Long int to int : higher order bits are dropped. To force a type conversion casting a value E.g., b = (double) sum / m; a = (int) a + b ; ----------xxxxxxxxx----------EXAMINATION QUESTIONS AND ANSWERS:

Q1.

With the help of a neat schematic diagram, explain the different functional units of a computer. (8-marks) Ans:Basic structure of a digital computer Memory Input unit Control Unit Out put unit

ALU

1. 2. 3. 4. 5.

A computer consists of five functionally independent main parts Arithmetic and logic unit Control unit Memory Input unit Out put unit

ALU contains electronic circuits necessary to perform arithmetic and logical operations.(Arithmetic operations are ADD , SUBTRACT, MULTIPLY ,DIVIDE ETC) Logical operations includes COMPARE, SHIFT, ROTATE, AND , OR etc. Control unit analysis each instruction in the program and sends the relevant control signals to all the units. ALU, Memory, Input, and Output unit shows the internal communication inside a computer. The program is feed into the computer through the input unit and stored in the memory. In order to execute the program, the instructions have to be fetched from memory one by one, this fetching is done by the control unit . Control unit decodes the instruction, According to the instruction , the

control unit issues control signals to other units. After instruction is executed, the result of the instruction is stored in memory or stored temporarily in the control unit, or ALU, the result of a program are taken out of the computer through the computer through the output unit.

Q2. Explain Von-Neumann concept. (4 marks) Ans:- Von Neumann Concept Von Neumann was a genius , he spoke many languages, was an expert in physical sciences and mathematics, and had total recall of every thing he ever heard, saw or read. He was a eminent mathematician in the world. He came to realize that programs could be represented in digital form in the computers memory, along the data. His basic design now known as a Von Neumann machine, was used in EDSAC, the first stored program computer and is still the basis for nearly all digital computers, the main contribution of Von Neumann is the idea of storing the program and the data in the same memory. Storing programme is essential if the instructions are to ve repetitively carried out. Storing program in the memory also makes computer automatic.

Q3. Differentiate between machine language and high level language.(3 marks) Ans:- i)Machine Language A computer understands information composed of only zeros and ones and hence it uses binary digits for its operation, The computers instructions are coded and stored in the memory in the form of 0s and 1s. A program written in the form of 0s and 1s is called machine language program, there is a specific binary code for each instruction. The binary code for a certain operation differs from computer to computer. Each microprocessor has its own instruction set and corresponding machine codes. ii) High level language The difficulties associated with assembly languages high level or procedure oriented languages have been developed. Instructions in HLL is called as statements Statements clearly resemble English and Mathematics HLL is independent of a computer; same program will run on any computer, which has a compiler Easier and faster to write Provide better documentation, and programs are portable.

Q4.

Explain any four DOS commands and its equivalent UNIX commands. (8marks) i) TYPE <file name> this command will list the contents of the file indicated after the type command equivalent Unix command which does the same is $ cat <file name> ii) DIR This command lists all the files and directories in the present drive , its equivalent in Unix is $ ls l iii)C:\> COPY file1 file2 This command copies the contents of file1 to file2, if the file2 doesnt exist it creates and copies. The equivalent Unix command is $ cp file1 file2 iv) DEL < file name > This command deletes the file specified, the Unix command is $ rm <filename>

Q5. Differentiate between primary memory and secondary memory.(2marks) Ans:- Primary memory Primary storage or main memory is a fast memory capable of operating at electronic speeds. Programme is stored in main memory during the execution. There are two types a) RAM b) ROM. RAM have both read and write capabilities and are volatile in nature( stored information is lost whenever power supply is withdrawn) ROM has only read capability and is non volatile , ROMs are used to store start up programs, system self testing routine etc. Ex :- PROM, EPROM etc,

Secondary memory
Main memory cannot hold large amounts of data at any particular moment, So they are stored in secondary memory from which date is fed to the main memory and when required by the CPU It is non volatile It cannot be directly accessed by the CPU Ex :- Floppy disk, Magnetic drum, tape drive etc, Q6. Differentiate between System software and application software. (2marks) Ans:- System software:-Is a collection of programmes that is executed as needed to perform functions such as Receiving the interpreting user commands Entering and editing applications Managing the storage and retrieval

Running standard applications Controlling I/O units Translating programmes Linking and running user written programmes System software is thus responsible for the coordination of all activities in a computing system, system software consist of operating system, compiler, assembler, interpreter, debugging programs, text editors etc.

Application software : An application package or application program is the software that has been written to process or perform a specific job, i.e. a program that is prepared by a programmer to solve certain problem. Application packages are available for all types of tasks. They may be business applications, engineering design , home applications, teaching aids etc. Ex : Word processing, CAD for designing and drafting, Dbase to work with records, to design building structure , power systems, inventory control , accounting, etc Q7. Differentiate between High level language and assembly level language (2marks) Ans:- High level language:The difficulties associated with assembly languages high level or procedure oriented languages have been developed. Instructions in HLL is called as statements Statements clearly resemble English and Mathematics HLL is independent of a computer; same program will run on any computer which has a compiler Easier and faster to write Provide better documentation , and programs are portable

Assembly language
It is more closely related to the structure of the computer, Programmer spends more time in manipulating registers etc than solving the given problem Programmer should have the detailed knowledge of the instruction set, architecture and connection of the peripherals to the ports etc. Q8. Differentiate between Compiler and interpreter. (4marks) Ans:- Compiler A program which translates a high-level language program into a machine language program is called a compiler. It is intelligent than assembler It checks all kinds of limits, ranges errors etc,

Occupies a large part of the memory, low speed an low efficiency of memory utilization.

Interpreter
It is a program which translates statements of a high level language program into machine code, It translates one statement of the program at a time. Compiler goes through the entire high level language once or twice and translates the entire programme into machine codes. Q9. Differentiate between Syntax error and logical error. (2marks) Ans:- Syntax error This type of errors are the result of violation of grammar (rules of the programming language), on encountering errors a computer displays error message specifying the line number. It is easy to debug these errors Logical errors Logical errors occur during coding process. Programmer should take care of correct operations to be performed. If any error after execution it produces unwanted result. It is difficult to debug such errors because computer does not display them. Q10. Write the commands to achieve the following an DOS and UNIX environments: (10 marks) Ans:- DOS COMMANDS UNIX COMMANDS Display the contents of an ASCII file. i) type <file name> List the contents of current directory. ii) dir Copy the contents of file 1 and file 2 iii) c:\> copy file1 file2 delete a file from current directory. iv) DEL < file name > rename a file by another name v) REN <oldname> <newname> cat <file name> ls l cp file1 file2 rm <filename> mv oldname newname

Q11. Write an algorithm to find i)the total number of even integers

(10 marks)

Ans:-

i) the total number of odd integers ii) the sum of all even integers iii) the sum of all odd integers from a given set of 100 integers Algorithm step 1 Step 2 Step 3 Step 4 step 5 step 6 step 7 Initialize the variables En=0,on=0,oddno=0,evenno=0,n=0; Read the no one by one If remainder ==0 (no % 2) = = 0 go to step 5 oddno ++ on+-no go to step 6 evenno ++ en + = no n ++ if n < 100 go to step 2 print the total no of even integers odd integers sum of odd numbers sum of even numbers stop

step 8

Q12. Pick the incorrect floating point constants and give reasons for the same (5marks) I) ii) 40,943.65 43 is invalid because comma is not allowed is invalid floating point constant, period is absent valid valid valid (5 marks)

iii) 428.58 iv) 46E2 v) 465.

Q13. Write an Algorithm to find the given no is prime or not. Ans:step 1 step 2 step 3 step 4 step 5 step 6 Q14. Read the no initialize variable flag =1 for I= 2,3,4, n/2 if (n % I) = = 0 flag = 0 if flag = = 0 , write no is not prime go to end print no is prime end

Write C expressions corresponding to the following (Assume all

quantities are of type float) i) (a * x + b) / ( a * x b ) ii) iii) iv) v) (2*x+3*y)/(x6)

(10 marks)

pow(x,5) + 10 * pow (x,4) + 8 * pow ( x,3) + 4 * (x + 2) ( 4 * x + 3 ) * ( 2 * y + 2 * z + 4) a / ( b * ( b a ))

Q15. Classify the following into valid and invalid variable names in C, if invalid give reasons i)int ii)$roll iii)_name I iv)Jamesbond v) I class (10marks) Ans:I) int - invalid (keyword) ii) $roll invalid (blank space in the middle) iii)_na me invalid (blank space in name) iv) Jamesbond invalid ( quote in the string) vi) 1class invalid (first char is numeral) Q16. What would be the value of d after the execution of the following expressions. Assume the initial value of a=5; (6marks) Ans:- a) a + = (a++) + (++a); ans=19 b) a- = (--a) (a--); ans=3 Q17. For the following program segment give an equivalent program segment using the switch statement. (6marks) if (opr==1) Res = a+b; else if (opr == 2) res=a-b; else if (opr == 3) res=a*b; else res = a/b; Ans:Switch (opr) { case 1: res=a+b; break; case 2: res=a-b; break; case 3: res=a*b; break; case 4: res=a/b; break; }

--------xxxxxxx---------

You might also like