Sie sind auf Seite 1von 29

SRI KRISHNA COLLEGE OF TECHNOLOGY

KOVAIPUDUR, COIMBATORE-641042
DEPARTMENT OF CSE & IT
TWO MARK QUESTIONS AND ANSWERS
SUBJECT CODE : 13H105
SUBJECT
: FUNDAMENTALS OF COMPUTING & CPROGRAMMING
CLASS
: I YEAR
UNIT I
INTRODUCTION TO COMPUTERS
1. What is a computer?
A computer is a data processor that accepts the input data (alphanumeric) or
instructions or both and performs the operations and displays the results of the
operation.
2. What are the advantages of computer?
The main advantages offered by computers are as follows:
High Accuracy
Superior Speed of Operation
Large Storage Capacity
User friendly Features
Portability
Platform independence
Economical in the long term
3. Mention the applications of computer
Education
sports
Advertising
Medicine
Entertainment
Government
Home
Science & Engineering
4. State the characteristics of computers
Speed
Accuracy
Automatic
Endurance
Versatility
Reduction of cost
5. Mention any two recent input & output devices
Input devices:
Touch pad, touch screen
1

Output devices:
Printer, plotters
6. Give the classification of computers.
Computer Type
Mainframe

Year of Introduction
1945

Mini Computer

1965

Micro Computer

1972

Personal Computer

1975

Laptop

1983

Palmtop

1990

Specific Computers
Mark1,B5000,IBM
s/360/370,CRAY-1,UNIVAC
1100,IBM 1401,ICL 1901,ICIM
2900
PDP-8,PDP-11,HP 2100A,TDC
312,TDC 316,HCL s-2/s-4
ORG 2001,ORG 80,WIPRO
86,SUPERMAX
APPLE,ALTAIR
8800,SINCLAIR,IBM PC
TRS-80 Model 100,IBM
5155,Compaq SLT/286, Zenith
Minisport, Mactinosh PowerBook
100,ThinkPad 700

7. Write the full forms of ENIAC, ALU, CU, RAM, ROM, EPROM, EEPROM, BIOS.
ENIAC Electronic Numerical Integrator and Calculator
ALU Arithmetic Logic Unit
CU Control Unit
RAM Random Access Memory
ROM Read Only Memory
EPROM Erasable Programmable ROM
EEPROM - Electrically Erasable PROM
BIOS Basic Input Output System
8. What is a CPU? What is its function?
The Central Processing Unit (CPU) takes data and instructions from the storage
unit and makes all sorts of calculations based on the instructions given and the
type of data provided. It is then sent back to the storage unit.
CPU, the brain of any computer system. It is just like brain that takes all major
decisions, makes all sorts of calculations and directs different parts of the
computer functions by activating and controlling the operations.
9. Define primary storage and secondary storage.
Primary storage is the main memory that holds running program instructions,
data, intermediate results, and results of ongoing processing of job(s). It is fast in
operation, Small Capacity, Expensive. It is Volatile (looses data on power
dissipation)

Secondary storage is the auxiliary memory that holds data and information of
stored jobs. It is slower than primary storage, Large Capacity, Lot cheaper that
primary storage. It is Non volatile (Retains data even without power)

10. What is the function of control unit?


It fetches program instruction from primary storage unit known as fetching,
interpret them and ensure correct execution of the program known as decoding.
The time required to fetch and decode an instruction is called instruction time, or
I-time.
11. What is the use of registers?
To speed up processing, the ALU uses registers (temporary storage locations) to
hold instructions and data.
Once processing begins, an instruction register holds instructions currently
being executed. A data register holds the data items being acted upon. A storage
register hold the immediate and final results of processing.
12. Define system software.
It is a set of programs designed to control the input and output operations of the
computer, communicate with the operator and schedule the resources of the
computer for continuous operation.
Examples are loader, linker, operating system, compilers, and interpreters.
13. What is an operating system and what are the functions of operating
system?
The most important system program is the operating system(OS) that controls all
the computer resources and provides the base upon which the application program
can be written and it hides all complexity to the users.
The functions of the OS are
1.
Process management
2.
Memory Management
3.
File Management
4.
Protection.
14. Define program
A process is a program in execution that will need certain resources such as CPU
time, memory files, and I/O devices to accomplish its task.
15. Define Assembler.
It is a translator which takes the input in the form of assembly language and
produces machine language as output.
Assembly Language Instructions Consists Of
Opcode(operation code) indicates the operation performed by the instructions
Mode and operand conveys the address of the data to be found or stored.
16. What is Compiler?
Compiler takes the source code and produces the machine language code for the
machine on which it is to be executed as the output.
During the process of translation, compiler checks the syntax error and this action
is known as diagnosis.
3

17. Define Application software with example


It is a set of program designed to perform a specific task or operation. Examples are
Microsoft office word,Adobe reader, VLC media player
18. Differentiate RAM & ROM
RAM is used for accessing and modifying data stored in the memory.
RAM is volatile memory
ROM is used only to read the data stored in the memory. It does no allow any
modifications to data.
ROM is non-volatile
19. Mention the different types of RAM
SDRAM(Synchronous Dynamic RAM)
DDRRAM(Double Data Rate RAM)
RDRAM(Rambus Dynamic RAM)
20. Mention different types of secondary memory
Hard-Disk drive
Floppy disk drive
CD-ROM drive
21. Mention different ways of representing the numbers
Decimal number system
Binary number system
Octal number system
Hexa decimal number system
22. State the different types of ROM
Semiconductor Read only memory (SROM)
Programmable Semiconductor Read only memory (PROM)
Erasable Programmable Semiconductor Read only memory(EPROM)
23.Define firmware with example
In electronic systems and computing, firmware is the combination of persistent
hardware , program code and data stored in it. Typical examples of devices containing
firmware are embedded systems (such as traffic lights, consumer appliances, and digital
watches, computers, computer peripherals, mobile phones , and digital cameras)
15. What is an algorithm?
An algorithm is part of the plan for computer program. It is an effective procedure
for solving a problem is a finite number of steps.
It helps the programmer in breaking down the solution of a problem into number
of sequential steps.
16. What are the ways of representing an algorithm?
Three different ways such as
Pseudocode
Flow chart
4

Nassi-Scheiderman
17. Define flowchart.
A flowchart provides an appropriate step to be followed in order to arrive at the
solution to a problem.
It is a program design tool used before writing programs.
A flowchart comprises a set of various standard shaped boxes that are
interconnected by flowlines.
18. What are the limitations of flowchart?
Complex logical problem sometimes becomes difficult for flowchart.
Alterations and modifications redraw flowchart completely
Reproduction of symbols becomes a problem
The essentials of what has to be done can easily be lost in the technical details of
how it is to be done.
19. Define a pseudocode.
Pseudocode, like step-form written statement of an algorithm using a restricted and
well defined vocabulary.
It is similar to a 3GL.
No standard but easy to read and use.
21. What is a sequence control structure?
Sequence means that each step or process in the algorithm is executed in the specify
order.
Eg. Algorithm to add any two numbers
Step 1 Accept the first integer as input from the user (integer1).
Step 2 Accept the second integer as input from the user (integer2).
Step 3 Calculate the sum of two integer (integer3= integer1+ integer2).
Step 4 Display the integer3 as the result
22. What is relocation?
It means adjustment of all address dependent locations such as address constant. It is
simpler in moving a program from one area to another in main memory.
23. What is a linker ?
Linking resolves symbolic references between the object programs.
References to build-in functions and global data requires linking in C eg. In
FORTRAN , COBOL are translated separately so subprogram cells and common
variables requires linking.
Linking makes the addresses of programs known to each other so that transfer of
control form one subprogram to another or a main program takes place during
execution.
24. What are the basic symbols used in flowchart?
Start or end of the program
Computational steps or processing function of a program
5

Input or output operation

Decision making and branching


Connector or joining of two parts of program
Magnetic Tape
Magnetic Disk
Off-page connector
Flow line
Annotation

Display

25. Mention any four advantages of using flowchart.


Communication is better using flowcharts.
Effective analysis.
Proper documentation.
Efficient coding.
Proper debugging.
Efficient program maintenance.
UNIT II
PROBLEM SOLVING METHODS
1. What are the Factors for Quality of Algorithm?
Time the better algorithm takes lesser time to compute.
Memory- the better algorithm take lesser memory to access.
6

Accuracy- multiple algorithm gives correct solution but only some algorithms
give actual output.
Sequence- procedure of an algorithm must form in a sequence.
2. What are the Groups used to perform logic constructions?
1. Sequence
2. Selection (If-then-else and case structure)
3. Iteration (while-do and repeat-until structure)
3.Define Sequencial construction.
Logic flow of pseudo code is from top to bottom
No conditional statements, jump or branch instructions used
Instructions are executed in sequential order
Simplest way to represent arithmetic or input/output statements
4. Define Selection construction.
Also called as decision logic
Used for decision making purposes
Tasks are performed if the given conditions are satisfied
Otherwise, alternative tasks are carried out
While constructing pseudo code, statements used for selection
logic are:
(i) If-then statement
(ii) If-then-else statement
(iii) Case statement
5. What are the Main reasons for using loop statements?
To easily read, write or process large data. Example: Array processing
To perform iterative computing
Business application, etc
6. What are the Classification of loops?
Definite loop
Indefinite loop
1. Definite loop:
Initial value within the loop is changing to meet the termination condition
Boolean expression is changing to meet the termination condition
2. Indefinite loop:
Loop construction never meets the termination condition
External operations such as reset, reboot are done to terminate the program
7. Give the pseudo code for if-then structure:
If condition then
Process 1
Else
Process 2
End if
7

8. List out the Classification of programming languages for computers:


Machine level programming
Assembly level programming
High level programming
9.Draw a diagram that depicts the evolution of programming languages.
Machine level programming

Assembly level programming

High level programming


10. Define Machine level programming.
1.
Machine code is the fundamental language of a
computer
2.
Written as strings of 0s and 1s
3.
Each instruction communicates to the control unit of
CPU
4.
Length and location of data fields along with what to be
done is involved with the above operation
5.
Common operations are reading, adding, etc
Format of this instruction is: Operation code
Operand
11. Define Assembly level (low-level) programming:
6.
It is designed to overcome the problems of machine
language
7.
Also called as symbolic programming language
8.
Uses symbolic names (mnemonics) instead of the binary
strings of machine code
9.
First symbolic programming language is assembly level
language
10.
Performs same logical steps as in machine code by using
a special software assembler
11.
Assembler translates and substitutes mnemonic
operation code for binary operation code
12. Define High level languages.
12.
Designed to overcome the restrictions of low level
programming
13.
Resembles English language in structure

14.

Single instruction at high level responds to several


instructions in machine language
15.
It is human readable form, so to translate into machine
code, compiler languages are used
16.
Also called as procedure oriented languages
17.
Compiler is a special software that is unique for every
high level language
18.
It performs the task of translation
19.
Example high level languages are BASIC, COBOL, C,
C++
13. Comparison of low level and high level languages:
S. No
1

3
4
5
6
7

Indicators
Program development
time
Programmers
skill
required
Orientation
Ease of modification
Speed of processing
Memory requirements
Portability of programs

Applications

Low level languages


Long

High level languages


Relatively short

High

Much lower

Towards computers
Difficult
Very high
Minimum
Programs are confined
machine
Operating systems (OS)

Towards humans
Very easy
Slower
Often significant
to Application
Application programs

14. What are all the Basic internet terms?


Web page
Website
Home Page
Browser
Uniform Resource Locator (URL)
Hypertext
Web Server
Download and upload
Online and offline
15. Define Web page.
WWW consists of files called pages or web pages
Web pages contain information and links to resources throughout the internet
A webpage is a electronic document written in a computer language called HTML
(Hyper Text Markup Language)
16. Define Website.
Set of related web pages published and owned by an organization or individual
9

It contains a homepage along with other additional web pages


It is accessed by its own address known as URL (Uniform Resource Locator)

17. What is Home Page?


Home page is the starting point or a doorway to the web site
Provides an overview of what could be found at the web site
Home page is also called as index page
18. What is Browser and mention its types ?
Web browser is a computer program that accesses web pages and displays them
It is the basic software that is needed to find, retrieve, view and send information
over the internet
Browsers are of two types:
1. Graphical browsers: allows retrieval of text, images, audio and video.
Example is Internet explorer.
2. Text browsers: provides access to the web in text-only mode. Example:
Lynx
19. Define Uniform Resource Locator (URL):
Each web page has a unique address called a uniform resource locator
(URL)
URL identifies its location on the internet
URL retrieves a file from the computer on which it resides
URL consists of six parts:
o Protocol: http
o World wide web : www
o Domain Name: xyz
o Domain type: com
o Path: home/start/ programs
o File Name: main.htm
20. Define Hypertext:
Hypertext refers to the text or image that connects to other documents
Hypertext or hyperlink or hotlink is used to jump to another part of the same
page or to load a different web page
Hypertext is a method of cross-referencing
21. Differentiate between Download and upload:
Download is an activity of moving or copying a document, program or other data
from the Internet or other interconnected computers to a computer
It is a process of pulling information from computer onto another
Upload is just the opposite of download

10

The user moves or copies a document, program or other data from a computer to
the internet
22. Differentiate between Online and offline:
Online means connected to the world wide web via internet
Any activity undertaken while the computer is connected to another computer
or network is said to be online
Offline means user is no longer connected to the remote computer
Offline is the opposite of online. It refers to the actions performed when the
user is not connected to another computer or a network like the internet
23. List out some of the Internet services:
World wide web (WWW)
Electronic mail (E-mail)
Internet relay chat (IRC)
Chatting and instant messaging
Internet telephony
Video Conferencing
24. What are the different Types of internet connection?
Dial-up
ISDN
Cable
Modem
Leased line
DSL
Broadband
25. What is an algorithm?
An algorithm is part of the plan for computer program. It is an effective procedure
for solving a problem is a finite number of steps.
It helps the programmer in breaking down the solution of a problem into number
of sequential steps.
26. What are the ways of representing an algorithm?
Three different ways such as
Pseudocode
Flow chart
Nassi-Scheiderman
27. Define flowchart.
A flowchart provides an appropriate step to be followed in order to arrive at the
solution to a problem.
It is a program design tool used before writing programs.
A flowchart comprises a set of various standard shaped boxes that are
interconnected by flowlines.
11

28. What are the limitations of flowchart?


Complex logical problem sometimes becomes difficult for flowchart.
Alterations and modifications redraw flowchart completely
Reproduction of symbols becomes a problem
The essentials of what has to be done can easily be lost in the technical details of
how it is to be done.
29. Define a pseudocode.
1. Pseudocode, like step-form written statement of an algorithm
using a restricted and well defined vocabulary.
2. It is similar to a 3GL.
3. No standard but easy to read and use.
30. What is a sequence control structure?
Sequence means that each step or process in the algorithm is executed in the
specify order.
Eg. Algorithm to add any two numbers
Step 1 Accept the first integer as input from the user (integer1).
Step 2 Accept the second integer as input from the user (integer2).
Step 3 Calculate the sum of two integer (integer3= integer1+ integer2).
Step 4 Display the integer3 as the result
31. What is relocation?
1. It means adjustment of all address dependent locations such as address constant. It
is simpler in moving a program from one area to another in main memory.
32. Mention any four advantages of using flowchart.
Communication is better using flowcharts.
Effective analysis.
Proper documentation.
Efficient coding.
Proper debugging.
Efficient program maintenance.
UNIT III
INTRODUCTION TO C PROGRAMMING
1. Give any four features of C language.
1. C is a general purpose, structured programming language.
2. C is powerful, efficient, compact and flexible.
3. C is highly portable.
4. C is a robust language whose rich set of built in functions and operators can be
used to write any complex programs.
2. Define comments?
Comments are very helpful in identifying the program features and underlaying
logic of the program. The lines begins with /* and ending with */ are known as

12

comment lines. These are not executable, the compiler is ignored any thing in
between /* and */
Ex: // Sample comment line
/* program for adding two numbers*/
3. What is meant by C tokens?
The tokens are usually referred as individual text and punctuation in a passage of
text. The C language program can contain the individual units call the C tokens.
Ex: operator, string, constant, identifier
4. Define data types.
Data type is the type of the data, that are going to access within the program. C
supports different data types, each data type may have predefined memory
required and storage representation.
5. Define identifiers.
Identifiers are names given to various program elements, such as variables,
functions and arrays etc.
Ex: basic_pay, num1, sum
6. What are keywords?
Keywords are certain reserved words, that have standard and pre-defined meaning
in C. These keywords can be used only for their intended purpose.
Ex: int, float, static, extern, const
7. Why do we need to use comments in programs?
To increase readability and understandability.
To help users in debugging and testing.
8. Write down the syntax for Declaring a variable
Syntax: Datatype variablename;
Ex:
int a;
9. Write the use of scanf & printf with example?
The scanf statement is used to get the input from the standard input
device..
The printf statement is used to print the result on the standard output
device.
Example:
scanf(%d, &a);
printf(Result:, a);
10. What is meant by variables? How and where are the variables
declared?
A variable is an identifier that is used to represent some specified type of
information within a designed portion of the program.
Variables are declared along with its data type at the beginning of the
program.
Ex: data_type variable _name;
Where data type represents the type of data,
variable_name is the valid C identifier.
13

11. Give the Rules of declaring variable or identifier:


The variable must start with letter or underscore (ex: int _x, char fruit) The
variable can have numbers (ex: int res2)
The variable cannot have key word as identifier (ex: float do) because do is key
word.
The variable name must be unique in their location local or global. That is
variable cannot have same name in the local declaration part or in the global
declaration part of any data type.
Give meaningful name to the variable for easy identification (ex: int gi_total),
here prefix g stands for global, and i for integer, and the name.
The variable cannot have special characters like %, $, # etc. (ex: int rf_$s is
invalid)
No space between letters (ex: int ap ple; is invalid declaration)
Length of the variable name 31 characters.
12. What is global variable?
The variables which are declared outside of all the functions is called global
variables. These variables are used any where in the program.
Ex: int a=5;
main()
{
printf(%d,a);
display();
}
display()
{
a=a+5;
}
13. What is local variable?
The variables which are declared with in a function is called as local variable.
These variables cannot be accessed outside the function.
Ex:
main()
{
int a=5;
display();
}
display()
{
int c;
}
Where a and c are local variables. Variable a cannot be used in the function
display().
14. Define constants? How they differ from variables?
14

The items whose values cannot be changed during the execution of program are
called constants.
Ex: 10, 10.2, a, it
The value stored in the variable can be changed during the
execution of the program.
15. Define String constants.
A string constant is a sequence of characters enclosed in double quotes, the
characters may be letters, numbers, special characters and blank spaces etc. at the
end of string \0 is automatically placed.
Ex: sangee, 123, , $%^
16. List out the various backslash character constants.
\n
- Newline
\t
- Tab
\b
- Backspace
\f
- Form feed
\r
- Carriage return
\a
- Alert
\
- Single quote
\
- Double quote
\\
- Backslash
17. What is an operator and operand?
An operator is a symbol that specifies an operation to be performed on operands.
Ex: *, +, -, / are called arithmetic operators.
12. The data items that operators act upon are called operands.
Ex: a+b; In this statement a and b are called operands.
18. What are the types of operator?
Arithmetic operators
Relational operators
Logical operators
Assignment operators
Increment and decrement operators
Conditional operator(Ternary operator)
Bitwise operators
Special operators.
19.What is Ternary operator?
Ternary operator is a conditional operator with symbols? and:.
Syntax: variable = exp1? exp2: exp3
If the exp1 is true, variable takes the value of exp2. if the exp1 is false,
variable takes the value of exp3.

15

20. Define expression.


1. An expression represents data item such as variables, constants and are
interconnected with operators as per the syntax of the language. An expression
is evaluated using assignment operator.
Ex : c = a+b
21.What is the output of the following?
main()
{
int x=100, y=200;
Printf(%d,(x>y)?x:y);
}
Output: 200
22. Define Precedence and Associativity:
2. Precedence is a priority given to the operators. Each operator has different
priorities. In an expression priority is given based on the operators used.
Therefore care must be taken to avoid logical error when using complex
expression with operators.
Example: x = (s+10) * (r+t)
The processing will be as follows
Step1: s+10 will be processed
Step2: r+t will be processed
Step3: results of step1 and step2 will be multiplied
Step4: the final result value will be assigned to x
From the above example it is clear that the following operators (), *, +, and = are
used.
The first operation was (s+10), the second operation was (r+t), and the third
operation was * and the last operation was =.
Therefore for the above example the highest priority was given to expression
within ( ) and last priority was given to = (assigning operator). This process of
flow of operation among the operators is called precedence.
The direction at which the operators are processed is called associativity. The
above example showed that ( ) moved from left to right, and operator equal (=)
from right to left.
23. What is meant by operator precedence?
1.
Operator precedence describes the order in which C evaluates
different operators in a complex expression.
24. What is associativity? What is the associativity of unary
operators?
Associativity can be either left to right or right to left.
16

Associativity is used only when the operators are of same precedence.


The associativity of unary operator is right to left.
25. What do u meant by left to right associativity and right to left
associativity?
1)
Left to right associativity evaluates the expression by starting on the left
and moving to the right.
2)
Right to left associativity evaluates the expression by starting on the
right and moving to the left.
26. What is the purpose of control string in a scanf function?
2.
It indicates that what type of data is to be read. It is always
preceded with % sign
27. What are the types of I/O statements available in C?
There are two types of I/O statements available in C

Formatted I/O statements Ex: scanf( ), printf( )

Unformatted I/O statements.

Ex: getchar( ), putchar( ), gets( ), puts( )


28. Define single characters input getchar() function.
1.
The getchar() function is written in standard I/O library. It reads a single
character from a standard input device. This function do not require any
arguments, through a pair of empty parentheses, must follow the statement
getchar().
29. Define single characters output putchar() function.
2.
The putchar() function is used to display one character at a time on the
standard output device. This function does the reverse operation of the single
character input function.
30. What is the difference between scanf() and gets() function?
In scanf() when there is a blank was typed, the scanf() assumes that it is an end.
Gets() assumes the enter key as end. That is gets() gets a newline (\n) terminated
string of characters from the keyboard and replaces the \n with \0.
31. Define Printf Function.
1. Output data can be written from the computer onto a standard output device
using the library function Printf . Printf function moves data from the
computers memory to the standard output device whereas the scanf function
enters data from the standard input device and stores it in the computers
memory.
32.Write down the syntax of Printf Function.
2. The printf function is written as
17

printf(control string, arg7, arg2, . . . , argn)


3. The control string refers to a string that contains formatting information and
arg1, arg2, . . . , argn are arguments that represent the individual output data
items.
33.Write a simple program that makes use of Printf Function.
#include <stdio.h>
#include <math.h>
main()
{
float i= 2.0, j = 3.0;
printf( " % f %f %f %f", i,j, i + j, sqrt( i + j ) ) ;
}
Output:
2.000000 3.000000 5.000000 2.236068
34.Write about Precision.
4. The precision is an unsigned integer that is always preceded by a decimal point.
If a minimum field width is specified in addition to the precision (as is usually the
case) then the precision specification follows the field width specification.
35.Write a Program to read and write a line of text.
#include <stdio.h>
main( )
{
char line[ 15 ] ;
gets(1ine);
puts(1ine);
}
Input: Have a Nice Day
Output: Have a Nice Day
36.Write a Program to read and write a line of text.
5. The program may require that a group of instructions be executed repeatedly until
some logical condition has been satisfied. This is known as looping.
37.Specify the Logical Operators in C.
6.
Logical Operators are also called as Logical Connectives. They are as
follows:
&& (AND)
||(OR)
! (UNARY NEGATION OPERATOR)
7.
The logical connectives are used to combine logical expressions, thus forming
more complex expressions.
18

38.What is the use of Conditional Operator?


8. The conditional operator ? : also makes use of an expression that is either true or
false. An appropriate value is selected, depending on the outcome of this logical
expression. This operator is equivalent to a simple if- else structure.
39.List out the three different kinds of Statements in C.
2) Expression Statements
3) Compound Statements
4) Control Statements
5) An expression statement consists of an expression followed by a semicolon. A
compound statement consists of a sequence of two or more consecutive
statements enclosed in braces ({ and }).
6) The enclosed statements can be expression statements other compound statements
or control statements. Most control statements contain expression statements or
compound statements including embedded compound statements.
40.Mention about if-else Statement.
9. The if - else statement is used to carry out a logical test and then take
one of
two possible actions depending on the outcome of the test (i.e., whether the
outcome is true or false). The else portion of the if - else statement is optional.
41.What is the syntax of simple if statement?
if ( expression) statement
10. The expression must be placed in parentheses, as shown. In this form, the
statement will be executed only if the expression has a nonzero value (i.e., if
expression is true). If the expression has a value of zero (i.e., if expression is false)
then the statement will be ignored. The statement can be either simple or
compound.
42.Specify the general form of an if statement which includes the else clause?
if (expression) statement 1 else statement 2
11. If the expression has a nonzero value (i.e., if expression is true), then statement 1
will be executed. Otherwise (i.e., if expression is false), statement 2will be
executed.
43.Write about while statement.
12. The while statement is used to carry out looping operations in which a group of
statements is executed repeatedly until some condition has been satisfied.
44.Mention the syntax of while statement.
while ( expression) statement
19

13.

The statement will be executed repeatedly as long as the expression is true (i.e., as
long expression has a nonzero value). This statement can be simple or compound,
though it is usually a compound statement.

45.Write down a simple program to display the integers 0 through 9.


#include <stdio.h>
main( )
{
int digit = 0;
while ( digit <= 9)
printf( "%d\n", digit++) ;
}
46.Why there is a need for do-while statement.
14. When a loop is constructed using the while statement, the test for continuation of
the loop is carried out at the beginning of each pass.
15. Sometimes, however, it is desirable to have a loop with the test for continuation at
the end of each pass. This can be accomplished by means of the do - while
statement.
47.Write down the syntax of do-while statement.
o The general form of the do - while statement is
do statement while (expression);
o The statement will be executed repeatedly, as long as the value of expression is true
(i.e., is nonzero). Notice that statement will always be executed at least once since
the test for repetition does not occur until the end of the first pass through the loop.
o The statement can be either simple or compound though most applications will
require it to be a compound statement.
48. Write a note on for Statement.
1. The for statement is the most commonly used looping statement in C. This
statement includes an expression that specifies an initial value for an index another
expression that determines whether or not the loop is continued and a third
expression that allows the index to be modified at the end of each pass.
49. Give the general form for the for statement.
2. The general form of the for statement is
for ( expression 1; expression 2; expression 3) statement
3. Typically, expression 1is an assignment expression, expression 2 is a logical
expression and expression 3 is a unary expression or an assignment expression.
4. When the f o r statement is executed, expression 2is evaluated and tested at the
beginning of each pass through the loop and expression 3 is evaluated at the end
of each pass.

20

50.Write about Nested Control Structures.


1.

Loops like if-else statements can be nested one within another. The inner and
outer loops need not be generated by the same type of control structure. It is
essential that one loop can be completely embedded within the other - there can
be no overlap.
2.
Each loop must be controlled by a different index. Moreover nested control
structures can involve both loops and if - else statements.
3.
A loop can be nested within an if-else statement and an if-else statement can
be nested within a loop. The nested structures may be as complex as necessary, as
determined by the program logic.
51. What is the purpose of the switch statement?
The switch statement causes a particular group of statements to be chosen from
several available groups. The selection is based upon the current value of an
expression which is included within the switch statement.
The general form of the switch statement is
switch (expression) statement
where expression results in an integer value. Note that expression may also be of
type char, since individual characters have equivalent integer values.
52. Define break statement. Give an example.
The break statement is used to terminate loops or to do -while, or switch
statement. The break statement is written simply as
break;
without any embedded expressions or statements.
Eg.
switch (choice = toupper(getchar0))
{
case ' R :
printf( "RED" ) ;
break;
case ' W ' :
printf("WH1TE");
break;
case B ' :
printf ( "BLUE") ;
break;
default :
printf ( ERROR");
break;
}
53. Define Continue Statement. Give an example.
The continue statement is used to bypass the remainder of the current pass
through a
loop. The loop does not terminate when a continue statement is
21

encountered. Rather, the remaining loop statements are skipped and the
computation proceeds directly to the next pass through the loop.
The continue statement can be included within a while, a do - while or a f o r
statement. It is written simply as
continue;
without any embedded statements or expressions.
Eg:
for(count = 1; x <= 100; ++count) {
scanf ( "%f &x) ; 'I,
if (x < 0) {
printf("ERR0R - NEGATIVE VALUE FOR X " ) ;
continue;
}
54. Define Comma operator.
The comma operator (,) which is used primarily in conjunction with the for
statement. This operator permits two different expressions to appear in
situations where only one expression would ordinarily be used.
for( expression 7a, expression 7b; expression 2; expression 3) statement
where expression la and expression 7b are the two expressions, separated by
the comma operator,
where only one expression (expression I) would normally appear. These two
expressions would typically initialize two separate indices that would be used
simultaneously within the for loop.
55. What is palindrome?
A palindrome is a word, phrase or sentence that reads the same way either
forward or backward. For example, words such as noon, peep, and madam are
palindromes.
56. Define goto statement.
The goto statement is used to alter the normal sequence of program execution
by transferring control to some other part of the program.
In its general form, the goto statement is written as
goto label;
where label is an identifier that is used to label the target statement to which
control will be transferred.
Eg.
scanf ( "%fI" , &x) ;
while (x <= 100) {
.....
if ( x < 0) goto errorcheck;
.....
scanf ( "%fI" , &x) ;
}
error detection routine */
22

errorcheck: {
printf("ERROR - NEGATIVE VALUE FOR X " ) ; }
UNIT IV & V
ARRAYS AND STRINGS
1. What is a Pointer in C?
A pointer is a variable that represents the location (rather than the value) of a data
item, such as a variable or an array element.
A pointer is a data type whose value refers directly to (or "points to") another
value stored elsewhere in the computer memory using its address.
A pointer references a location in memory, and obtaining the value at the location
a pointer refers to is known as dereferencing the pointer
2. What are the advantages of using Pointers in C?
5. Pointers can handle arrays and data table efficiently.
6. Pointers support dynamic memory management.
7. Pointer helps to return multiple values from a function through function argument.
8. Pointer increases program execution speed.
9. Pointer is an efficient tool for manipulating structures, linked lists, queues stacks
etc.
3. What kind of information is represented by a pointer variable?
Pointer Variable is a variable that contains the memory location(address) of
another variable or an array (or anything else in memory). Effectively, it points to
another
memory
location.
4. List out some of the operations on pointers?
o A pointer variable can be assigned the address of an ordinary variable.
o A pointer variable can be assigned the value of another pointer variable provided
both pointers point to objects of the same data type.
o An integer quantity can be added to or subtracted from a pointer variable.
o A pointer variable can be assigned a null (zero) value.
o One pointer variable can be subtracted from another provided both pointers point
to elements of the same array.
o Two pointer variables can be compared provided both pointers point to objects of
the same data type.
5. Write notes on Address operator an indirection operator.

Suppose 'a' is a variable that represents some particular data item. The
compiler will automatically assign memory cells for this data item. The data item
can be accessed if we know the location of the first memory cell. The address of
23

as memory location can be determined by the expression &v, where & is a unary
operator called the address operator, that evaluates the address of its operand.
Now let us assign the address of 'a' to another variable, Thus
pa= &a;
This new variable is called a pointer to 'a', since it points to the
locations where 'a' is stored in memory. However, pa represents as address, not its
value. Thus, pa is referred to as a pointer variable.
Address of a value of a
pa
a
The data item represented by 'a' ( i.e the data item stored in as
memory cells) can be accessed by the expression *pa, where * is a unary operator,
called the indirection operator, that operates only on a pointer variable. Therefore,
*pa and 'a' both represent the same data item (ie the contents of the same memory
cells).
Further more if we write pa= &a and b = *pa, then 'a' and 'b' will both
represents the same value i.e the value of a will indirectly be assigned to 'b'

9. How do you declare a pointer in C?

A pointer declaration may be written in general terms as datatype *ptr; Where ptr
is the name of the pointer variable and data-type refers to the data type of the
pointers object.
For example,
float a,b;
float *pb;
The first line declares a and b to be floating-point variables. The second line
declares pb to be a pointer variable whose object is a floating-point quantity i.e.
'pb' point to a loating point quantity. 'pb' represents an address, not a floatingpoint quantity. Within a variable declaration, a pointer variable can be initialized
by assigning it the address of another variable.

10. Write notes on passing pointers as arguments.

Pointers are often passed to a function as arguments. This allows data items
within the calling portion of the program to be accessed by the function, altered
within the function, and then returned to the calling portion of the program in
altered form.
11.Differentiate Actual & Formal Arguments.
Actual parameters are parameters as they appear in function calls.
Formal parameters are parameters as they appear in function declarations.
A parameter cannot be both a formal and an actual parameter, but both formal parameters
and actual parameters can be either value parameters or variable parameters.

24

#include <stdio.h>
int main (void);
int calculate_bill (int, int, int);
int main()
{
int bill;
int fred = 25;
int frank = 32;
int franny = 27;
bill = calculate_bill (fred, frank, franny);//actual parameters.
printf("The total bill comes to $%d.00.\n", bill);
}

exit (0);

int calculate_bill (int diner1, int diner2, int diner3)


//Formal parameters.
{
int total;
total = diner1 + diner2 + diner3;
return total;
}

12.Difference between Call by reference & value.


Passing argument to function
1) In a c programming we have different ways of parameter passing
schemes such as call by value and call by reference.
2) Function is good programming style in which we can write reusable
code that can be called whenever require.
3) whenever we call a function then the sequence of executable
statement gets executed we can pass some of the information to the
function for processing called argument
Two ways of passing argument to function in c language
1) call by value
2) call by reference
call by value:
eg:
#include<stdio.h>
void interchange(int num1,num2)
{
int temp;
temp=num1;
num1=num2;
num2=temp;

25

int main()
{
int num1=50,num2=70;
interchange(num1,num2);
printf(\n number1:%d,num1);
printf(\n number2:%d,num2);
return(0);
}
output:
number1:50
number2:70
explanation:
A: call by value:
1)while passing parameter using call by value,Xerox copy of original parameter is
created and passed to the called function.
2)any update made inside method will not affect the original value of variable in
calling function.
3)in the above example num1&num2 are the original values is value passed to the
function and these vaues are copied into number1,number2 variable of sum function
respectively.
4)as their scope is limited to only function so they cannot alter the values inside main
function.
B:call by reference:
eg:
#include<stdio.h>
void interchange(int * num1,*num2)
{
int temp;
temp=*num1;
num1=*num2;
num2=temp;
}

int main()
{
int num1=50,num2=70;
interchange(&num1,&num2);
printf(\n number1:%d,num1);
printf(\n number2:%d,num2);
return(0);
}
26

output:
number1:70
number2:50
explanation:
call by address:
1.while passing parameters using call by address scheme,we are passing the actual
address of the variable to the called function.
2.any updates made inside the called function will modify the original copy since we are
directly modifying the content of the exact memory location.
summary of call by value and call by reference
point
copy
modification

Call by value
Duplicate copy of original
parameter is passed
No effect on original
parameters after modifying
parameter in function

Call by reference
Actual copy of original
parameter is passed
Original parameter gets
effected if value of parameter
changed inside function

UNIT V
13.What is a structure? How does a structure differ from an array?
Structure declarations are somewhat more complicated than array
declarations, since a structure must be defined in terms of its individual members. In
general terms, the composition of a structure may be defined as
struct tag
{
member 7;
member 2;
.....
member m;
};
Array elements are of the same data type whereas the individual elements
can differ in type in structure.
12. How is an array of structures initialized?
struct account
{
int acct-no;
char acct-type;
char name[80];
float balance;
27

struct date lastpayment;


} customer[ 100] ;
In this declaration customer is a 100-element array of structures. Hence, each
element of customer is a separate structure of type account (i.e., each element
of customer represents an individual customer record).
Note that each structure of type account includes an array (name [80]) and
another structure (date) as members. Thus, we have an array and a structure
embedded within another structure, which is itself an element of an array.

if a structure member is an array, then an individual array element can be


accessed by writing
variable. member[ expression]

where expression is a nonnegative value that indicates the array element.


13.What is the purpose of the typedef feature? How is this feature used in conjuction
with structures?

The typedef feature allows users to define new data-types that are
equivalent to existing data types. Once a user-defined data type has been
established, then new variables, arrays, structures, etc. can be declared in
terms of this new data type.

In general terms, a new data type is defined as


typedef type new- type;

where type refers to an existing data type (either a standard data type, or
previous user-defined data type),and new- type refers to the new user-defined
data type. It should be understood, however, that the new data type will be
new in name only. In reality, this new data type will not be fundamentally
different from one of the standard data types.
14.How can an entire structure be passed to a function and returned from a function.?
There are several different ways to pass structure-type information to or from
a function. Structure members can be transferred individually, or entire
structures can be transferred.
The mechanics for carrying out the transfers vary, depending on the type of
transfer (individual members or complete structures) and the particular
version of C.
Individual structure members can be passed to a function as arguments in the
function call, and a single structure member can be returned via the return
statement.
To do so, each structure member is treated the same as an ordinary singlevalued variable.
15.What is a union? How does a union differ from a structure?

Unions, like structures, contain members whose individual data types may
differ from one another. However,the members within a union all share the
28

same storage area within the computers memory, whereas eachmember


within a structure is assigned its own unique storage area.
Thus, unions are used to conserve memory. They are useful for applications
involving multiple members, where values need not be assigned to all of the
members at any one time.Within a union, the bookkeeping required to store
members whose data types are different (having different memory
requirements) is handled automatically by the compiler.
However, the user must keep track of what type of information is stored at any
given time. An attempt to access the wrong type of information will produce
meaningless results.

29

Das könnte Ihnen auch gefallen