Upload
rajesudhakar
View
227
Download
0
Embed Size (px)
Citation preview
8/10/2019 2 Marks Final
1/21
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
E6151- COMPUTER PRO RAMMMIN
TWO MARKS
UNIT 1
1. Define Computer. Give it e!p"nion.
The computer is an electronic device designed in such a way that it automatically accepts and stores input dat
process them and produce the desired output.
COMPUTER: Commonly Operating Machine Particularly Used or Trade and Education Research.
#. Define D"t" "n$ Inform"tion.
!ata: "t is the acts a#out anything.$raw data%
"normation: The processed data is called inormation.
%. W&"t "re t&e '"i( Oper"tion of " (omputer)
&."nput
'.Process
(.Output
).*toring
+.Controlling
*. W&"t i input "n$ output)
"nput is the process o capturing the raw data or inormation. y using this we can do any process.
Output is the result which comes rom the transormation process.
Transormation is the process in which input is converted into output.
+. Define torin,.
*toring is the process o saving the data or inormation, so that they can #e retrieved whenever needed.
-. Define (ontroin,.
Controlling is the process o directing the manner in which all the operations are to #e perormed.
/.W&"t "re (&"r"(teriti( of (omputer)
The characteristic o the computers are speed, accuracy, automation, endurance, storage, versatility, cost reductio
no intelligent -uotient"/0.
0. Give t&e "ppi("tion of (omputer. 1ord processing
"nternet
!igital video or audio composition
1eather analysis
Mar2et 3nalysis
&
8/10/2019 2 Marks Final
2/21
3ccounting
. Define 2"r$3"re "n$ Soft3"re.
The term 2"r$3"reis applied to any p&4i(" e5uipmentin the computer system, such as machinery.
Soft3"re is #asically 4t&e et of intru(tion ,roupe$ into pro,r"m that ma2e the computer to unction in th
desired way. "t is a collection o programs to perorm a particular tas25.
16. Give t&e 7"i( (omputer fun(tion" unit)
"nput Unit
Central Processing Unit
Output Unit
11. Define t4pe of pro,r"mmin, "n,u",e.
Machine 6anguage: "t uses only 7s and &s to represent data and the instructions.
3ssem#ly 6anguage: "t uses only mnemonic codes to represent data and the inormation.
8igh96evel 6anguage: These 6anguages are written using a set o words and sym#ols #y accessing speci
rules and synta.
1#. 8it out t&e oper"tion performe$ 74 t&e (entr" pro(ein, unit.
"t perorms all calculations and all decisions.
"t controls and co9ordinates all units o the computer.
"t interprets instructions o a program.
"t stores data temporarily and monitors eternal re-uest.
1%. Define oper"tin, 4tem.
3 collection o programs used to control and co9ordinate the computer system is called operating system. Operatin
system manages and coordinates the unctions perormed #y the computer system hardware, ";O devices, including the CPU
secondary storage devices, communication and networ2 e-uipment.
1*. Define 7it 9 74te)
'it:its is 2nown as #inary digit. Each #it value can #e 7 or &
'4te :ytes are most commonly made up o eight #its used to store a single character.
1+. Define RAM.
Random 3ccess Memory R3M0 is a temporary memory where the computer stores all the data it receives rom inp
and the results it gets through calculations.
1-. Define ROM.
Read Only Memory ROM0 is permanently in9#uilt in the computer at the time o production. "t stores a set o
instructions permanently which instructs the computer how to wor2.
1/. W&"t "re t&e t4pe of ROM)
PROM < Programma#le ROM
EPROM < Erasa#le PROM
'
8/10/2019 2 Marks Final
3/21
EEPROM* < Electrically Erasa#le PROM
=lash ROM*.
10. Differenti"te 7et3een t"ti( "n$ $4n"mi( RAM.
S.No St"ti( RAM D4n"mi( RAM
&. Retain its content as long as power is availa#le. "t has short data lie.
'. Constantly maintained data. >eed to #e rereshed to maintain data in it.
(. 6ess num#er o chips used. More num#er o chips used.
). ?ery ast. *low compared to *tatic R3M.
1. Differenti"te 7et3een RAM "n$ ROM.
#6. Define ("(&e memor4)
3 small memory #etween CPU and main memory is called cache memory. The access time is closer to the processin
speed o the CPU. Cache memory acts as a high speed #uer #etween CPU and main memory. "t is used to temporarily stor
active data and instructions during processing.
#1. 8it out t&e ("7e ue$ to (onne(tin, (omputer 3it& perip&er")
Power card
Monitor ca#le
Mouse ca#le
@ey#oard ca#le
Printer ca#le
##. W&"t "re t&e fun(tion performe$ 74 t&e input unit)
The input unit accepts data and instructions rom the user and convert it into a orm that the computer can understan
and then supply the converted data to the computer or urther processing.
"nput unit consists o one or more input devices. *ome o the input devices are: @ey#oard, Mouse , 6ight Pen,
Trac2#all etc.
#%.W&"t "re t&e fun(tion performe$ 74 t&e output unit)
The output unit provides the inormation and results o a computation to the user.
The output unit also converts the #inary data output into a orm that the user can understand.
*ome o the output devices are: printer, monitor, hard dis2 etc.
(
S.No ROM RAM
&. "t is a non9volatile memory "t is a volatile memory
'. The content are permanent The content are temporary
(. 3vaila#le in high storage capacity 3vaila#le in small storage capacity
). Processor speed is low Processor speed is high
+. Cost eective Cost is very high
8/10/2019 2 Marks Final
4/21
#*. W&"t i A,orit&m)
3n algorithm is the step #y step instructions o a program. 3lgorithm means the logic o a program. "t is
step9#y9step description o how to arrive at a solution o a given pro#lem.
#+. Define fo3(&"rt.
"t is a pictorial representation o an algorithm. "t contains some standard sym#ols. The steps are drawn #
using dierent shapes and the low is indicated #y arrows.
#-. W&"t i Peu$o(o$e)
4Pseudo5 means imitation o alse and 4code5 reers to the instruction written in the programmin
language. Pseudo code is programming analysis tool that is used or planning program logic.
NUM'ER S;STEM
&. Convert 'AA.'+0 &7 to octal orm
'. Convert &73)0&Ato #inary orm
(. Convert &&7&&&0'to decimal e-uivalent
). Convert &&77&&&&.&&0'to octal orm
F8OW C2ARTS
&. !raw the lowchart to ind the #iggest among two num#ers.
'. !raw the lowchart to reverse a given multi9digit num#er.
(. !raw a lowchart to ind the roots o the -uadratic e-uation.
). !raw a lowchart to ind the num#er is prime or not.
)
8/10/2019 2 Marks Final
5/21
UNIT #
1.Define Pro7em formu"tion.
Pro#lem ormulation is a plan or collecting re-uirements and utiliBing data a#out a pro#lem.
"t helps to o#tain the desired inormation a#out the pro#lem.
#.Define Pro7em ovin,.
"t is the process o transorming the description o a pro#lem into a solution #y using our 2nowledge o the pro#lem
domain #y using appropriate techni-ues and tools.
%.W&"t i $o(ument"tion)
"t provides a written description o each step o the program.
"t allows the user to operate the program correctly.
*. Give "n4 four fe"ture of C "n,u",e)
6ow level language support.
*tructured programming.
Program porta#ility.
Compactness, Reusa#ility 3ccepta#ility.
+. W&"t "re t&e m"
8/10/2019 2 Marks Final
6/21
0. Write t&e tep to (ompie " C pro,r"m.
Preprocessing, Compiling , 3ssem#ling, 6in2ing.
. W&"t i prepro(ein,)
"t is the irst stage o compilation.
"t includes header iles li2e stdio.h , conio.h etc.
"t processes all the preprocessor statements. Eample: Finclude, F deine etc.
16. Define (ompier.
"t is a program, which is used to convert the high9level language programs into machine language.
"t ta2es the output o the preprocessor and generates assem#ly code.
11. Define Aem7er.
"t is a program, which is used to convert the assem#ly level language programs into machine language.
"t ta2es the assem#ly code and generates #inary output.
1#. Define Interpreter.
"t is a program, it ta2es one statement o high9level language program, translates it into machine language instructio
and the immediately eecutes the resulting machine language instruction and so on.
1%. W&"t i in=er)
"t is a program, it ta2es one or more o#Gect iles as input and com#ines them to produce a single eecuta#le ile.
1*. W&"t i me"nt 74 C (&"r"(ter et)
3 character set deines the valid characters that can #e used in source program.
"t includes alpha#ets, digits and special characters.
1+. W&"t i me"nt C to=en)
C to2ens are the #uilding #loc2s in C language which are constructed together to write a C program.
"t includes constants, identiiers, 2eywords, strings, operators, special sym#ols.
1-. Define i$entifier)
"dentiiers are names given to various program elements such as varia#le, unctions and arrays etc.
1/. Define (ont"nt) W&"t "re t&e t4pe of (ont"nt)
Constant means that it does not change during the eecution o program.
Types o constants are:
>umeric constants < integer constants, real constants
Character constants < single character constants, string constants
10. Define trin, (ont"nt.
3 se-uence or group o characters is used as a constant value which is written within dou#le -uotes.
Eample: char name H 4 prince5 I
A
8/10/2019 2 Marks Final
7/21
1. W&"t i me"nt 74 v"ri"7e)
?aria#les are memory locations used #y a program to store data.
3 uni-ue name should #e given to each varia#le #y the user.
*ynta: datatype varia#le9name I
#6. Define $"t" t4pe)
3 datatype is used to deine a varia#le #eore its use.
3 datatype will assign storage or the varia#le and deine the type o data.
Eample: int, loat
#1. W&"t "re $ifferent $"t" t4pe "v"i"7e in C)
"nt < integer num#ers
=loat < loating point num#ers
Char < characters
!ou#le < long loating point num#ers.
##. W&"t "re =e43or$)
There are some reserved words called 2eywords that have predeined meaning in C language which cannot #
changed. Eample: #rea2, continue, or etc.
#%. W&"t i " oper"tor "n$ "n oper"n$)
3n operator is a sym#ol that speciies an operation to #e perormed on operands.
Eample: J, 9, , ; are called arithmetic operators.
The data items that the operators act upon are called operands.
Eample: aJ#. "n this a and # are called operands.
#*. W&"t "re t&e t4pe of oper"tor)
3rithmetic operators
Relational operators
6ogical operators
3ssignment operators
"ncrement and decrement operators
Conditional operators Ternary operator 0
it wise operators
*pecial operators
#+. W&"t i $ifferen(e 7et3een o,i(" AND "n$ 7it 3ie AND)
K
8/10/2019 2 Marks Final
8/21
6ogical 3>! only used in conGunction with two epressions to test more than one condition. " #oth th
condition are true then returns one, i alse then return Bero. it wise 3>! only used in #it wise manipulation. "t i
an unary operator.
#-. Define e!preion
3n epression is a com#ination o varia#les, constants and operators.
3n epression is evaluated using assignment operator.
Eample: H a# O t"tement "v"i"7e in C)
=ormatted unctions print 0, scan 0
input;output unctions
Unormatted unctions gets 0, getchar 0,puts 0,putchar 0
#0. W&"t "re t&e $ifferen(e 7et3een 3&ie "n$ $o3&ie oop)
W&ie Do 3&ie
"n the while loop the condition is irsteecuted. " the condition is true then it eecutes
the #ody o the loop. 1hen the condition is alse
it comes out o the loop.
"n the doLwhile loop irst the statement iseecuted and then the condition is chec2ed. The doL
while loop will eecute at least one time even though
the condition is alse at the very irst time.
1hilecondition0
*tatementsI
N
!o
*tatementsI
Nwhilecondition0
#. Define nete$ for oop)
3 or loop contains another or loop inside in it, is called a nested or loop.
Eample:
main 0
int a$(%$(% H &,',(,),+,A,K,, NI
or iH7IiQ(IiJJ0
orGH7IGQ(IGJJ0
print4d5, a$i%$G%0I
N
%6. W&"t i me"nt 74 7re"= t"tement)
8/10/2019 2 Marks Final
9/21
The #rea2 statement is used to terminate the loop when the 2eyword #rea2 is used inside any c loop contro
automatically transerred to the irst statement ater the loop. rea2 is usually associated with an i statement.
%1. Define ,oto t"tement)
The goto statement transer control unconditionally rom one place to another place in the program.%#. W&"t i me"nt 74 (ontinue t"tement)
1hen continue statement is encountered inside a loop, control automatically passes to the #eginning o the loop.
%%.8it out t&e
8/10/2019 2 Marks Final
10/21
Unit III
1. Define "rr"4)
3n array is a collection o similar data items stored under a common name.
3 collection o elements #elonging to the same datatype is called array.
Eample: int mar2s$+%I
#. 2o3 to $e("re "n "rr"4) OR 2o3 to $e("re " 1D "rr"4 )
*ynta: ?$"t" t4pe@ ?"rr"4 n"me@ iBe
where ?$"t" t4pe@ reers to the type o the array varia#le.
?"rr"4 n"me@reers to the name o the array.
iBereers to the num#er o elements in the array.
Eample: int m"r=16
%. 2o3 to initi"iBe "n "rr"4) OR 2o3 to initi"iBe " 1D "rr"4 )
*ynta: $"t" t4pe "rr"4 n"me iBe v"ue1 v"ue#HH.. v"ue n
The values are speciied in the curly #race and they are separated #y commas.
Eample: int mar2s $+% H +7, A7, K7, 7, 7 NI
loat mar2s$+% H +7.+, A7.+, K7.+, 7.+, 7.+ NI
*.Write t&e ("ifi("tion of "rr"4)
3rrays can #e classiied into two types:
One dimensional array
Multi9dimensional array 9S two9dimensional, three9dimensional, n9dimensional.
+. Define OneJ$imenion" "rr"4)
&7
8/10/2019 2 Marks Final
11/21
The array which is used to represent and store data in a single dimension is called one dimensional array.
!eclaration o One dimensional array
*ynta: ?$"t" t4pe@ ?"rr"4 n"me@ iBe
Eample: int m"r=16
-. W&"t i me"nt 74 T3oJ$imenion" "rr"4)
The array which is used to represent and store data in two dimensions called two dimensional array.
!eclaration o Two dimensional array
*ynta: ?$"t" t4pe@ ?"rr"4 n"me@ ro3 iBe (oumn iBe
Eample: int "%%
/.2o3 to $e("re " #D "rr"4)
!eclaration o Two dimensional array
*ynta: ?$"t" t4pe@ ?"rr"4 n"me@ ro3 iBe (oumn iBe
where ?$"t" t4pe@ reers to the type o the array varia#le.
?"rr"4 n"me@reers to the name o the array.
ro3 iBereers to the num#er o rows in the array.
(oumn iBereers to the num#er o columns in the array.
Eample: int "%%
0. 2o3 to initi"iBe " #D "rr"4)
*ynta: ?$"t" t4pe@?"rr"4 n"me@ro3 iBe(oumn iBe v"ue1 v"ue#H v"ue n
The values are speciied in the curly #race and they are separated #y commas.
Eample: int a$(%$(%H &,',(,),+,A,K,,NI
. W&"t "re mutiJ$imenion" "rr"4)
3rrays with more than one dimension is are called multi9dimensional arrays.
Eample : '! array : int a$(%$(%
(! array : int a$(%$(%$(%
16. Comp"re t"ti( "rr"4 "n$ $4n"mi( "rr"4.
&&
8/10/2019 2 Marks Final
12/21
St"ti( Arr"4 D4n"mi( Arr"4
" the range o an array is included in the
array deinition, it is called static array.
" the range o an array is not included in the
array deinition, it is called dynamic array.
*tatic arrays cant #e changed. !ynamic arrays can #e changed during runtime.
11. W&"t i t&e nee$ of "n "rr"4 v"ri"7e)
"t is used to represent a list o num#ers or names
"t is also used represent the ta#ular data in two, three or more dimensions.
1#. Define trin,)
3 string is a group o characters.
"t is also called character array.
"t is enclosed within dou#le -uotes. Eg: 48ai5
1%. 2o3 to $e("re trin, v"ri"7e)
!eclaration 9 "t is the process o deining the string varia#le, the siBe o the string and its type.
*ynta: ?$"t" t4pe@ ?trin, n"me@ iBe
(&"r trin,Jn"me iBe
where (&"r J (&"r"(ter $"t"t4pe.
trin, n"me name o the sting user deined0
iBereers to the num#er o characters in the string.
Eample: char str$A%I
1*. 2o3 to initi"iBe trin, v"ri"7e)
"nitialiBation9"t is the process o assigning the values either character #y character or directly the string value.
(&"r trin, n"me iBe v"ue
(&"r tr+ Ln L" Lm Le >> values are assigned character #y character
(&"r tr+ n"me ;; entire string is directly assigned.
(&"r tr n"me >> siBe o the string is not mentioned.
1+.W&"t "re t&e 3"4 to re"$ " trin,)
1. ("nf Q #. ,et Q %. ,et(&"r Q
!einition: "t is a ormatted
input unction to read a single
character or word rom the input
"t is an unormatted
input unction to read a group
o characters until an enter 2ey
"t is an unormatted
input unction to read a single
character at a time.
&'
8/10/2019 2 Marks Final
13/21
device and the ormat o the
string is s .
is pressed.
*ynta:
scan 4s5, varia#le9name0I
*ynta:
getsvaria#le9name0I
*ynta:
varia#le9name H getchar 0I
1-.W&"t "re t&e 3"4 to 3rite " trin,)1. printf Q #. put Q %. put(&"r Q
!einition: "t is a ormatted
output unction to write a single
character or word to the output
device and the ormat o the
string is s .
"t is an unormatted
input unction to read a group
o characters until an enter 2ey
is pressed.
"t is an unormatted
input unction to read a single
character at a time.
*ynta:
print 4s5, varia#le9name0I
*ynta:
putsvaria#le9name0I
*ynta:
varia#le9name H putchar 0I
1/. 8it ome trin, fun(tion)
strlen 0 < string length
strcpy 09 string copy
strcat 09 string concatenation
strcmp 09 string comparison
strlwr 09 string lowercase
strupr 09 string uppercase
strrev 09 string reverse
strstr 0 9 su#string
10. W&"t i trin, "rr"4)
3 two dimensional array is used to create an array o strings.
Eample: char name$'7%$&7%I
8ere '7 is the num#er o strings and &7 is the maimum length o each string.
1.W&"t i ortin,)
*orting is the process o arranging a set o similar inormation into an increasing or decreasing order.
*ome commonly used sorting methods are #u##le sort, -uic2 sort, merge sort, insertion sort etc.
#6. Define e"r(&in,.
&(
8/10/2019 2 Marks Final
14/21
The process o inding a target element among a list o elements.
The commonly used searching methods are:
linear search.
#inary search.
#1. 8it t&e (&"r"(teriti( of "rr"4.
3ll the elements o an array share the same name.
3n array is reerred #y inde num#er.
3n array inde num#er always #egins with Bero.
3n array consists o continuous memory locations.
3rray memory siBe H siBe o datatype siBe o array.
##. Write " C pro,r"m to re"$ " trin, " input "n$ print t&e "me " output.
FincludeQstdio.hS
void main 0
char str$+7%Iprint4Enter a string50I
scan4s5,str0I
print4The entered string is s5, str0IN
#%. Write " C pro,r"m to revere " ,iven trin,.
FincludeQstdio.hS
FincludeQstring.hS
void main 0
char string$&7%H5god5Istrrevstring0Iprint4The reversed string is s5,string0I
N
#*.Write " C pro,r"m to (&e(= t&e trin, i p"in$rome or not
FincludeQstdio.hS
FincludeQstring.hS
void main 0
M
char s&$'7%,s'$'7%I
int resultIputsUEnter a *tringVnU0I
getss&0I
strcpys',s&0I
strrevs&0I
resultHstrcmps&,s'0I
iresultHH70
putsUThe Diven *tring is PalindromeVnU0I
&)
8/10/2019 2 Marks Final
15/21
else
putsUThe Diven *tring is >ot PalindromeVnU0I
getch 0I
N
Unit *
1. W&"t i Fun(tion)
3 set o instructions to perorm speciic tas2s that occur several times in the main program is called a unctio
=unctions are the #uilding #loc2s in a program. =unctions are also called as su#programs.
#. W&"t "re t&e t4pe of fun(tion)
1.Pre$efine$ fun(tion
Predeined unctions are created #y the person who designed and created C compiler. These are also called a
li#rary unctions. Eample: log0, sin0 etc.
#.Uer $efine$ fun(tion
User deined unctions are created #y user according to their re-uirements. They are used to perorm
particular tas2. They can #e given ater or #eore the main unction.
%. 2o3 to $efine " Fun(tion)
*ynta: returnWtype unctionWname parameterWlist0 ;; unction header
local declarationI
eecuta#le statementsI ;; unction #ody
returnI
N
*. 8it out t&e fun(tion protot4pe)
=unction without arguments and without return values.
=unction with arguments and without return values.
=unction with arguments and with return values.
=unction without arguments and with return values.
+. W&"t "re t&e t&ree eement of uer $efine$ fun(tion)
=unction deinition
=unction declaration
=unction call
-. W&"t i " p"r"meter) W&"t "re t&e t4pe of p"r"meter)
Parameters serve as input data to the unction to carry out the speciied tas2.
Parameters are classiied into two types. &. =ormal Parameters '. 3ctual Parameters.
/. W&"t i " me"nt 74 "(tu" p"r"meter "n$ form" p"r"meter)
&+
8/10/2019 2 Marks Final
16/21
The ormal parameters allow inormation to #e transerred rom the calling program. The parameters used in th
unction deinition.
The actual parameters are the arguments in the calling unction. The parameters used in the unction call.
0. W&"t "re t&e met&o$ of p"in, " p"r"meter)
1henever a unction is called, the se-uence o eecuta#le statements is eecuted. The values passed to a unction
processing are called argument.
The parameter passing methods are
&. Pass #y value or call #y value
'. Pass #y reerence or call #y reerence
. Differenti"te C" 74 v"ue "n$ C" 74 referen(e)
P" 74 v"ue P" 74 referen(e
The values are directly passed to a unction. "t is
also called call #y value.
The address o a varia#le is passed to a unction. "t
is also called call #y reerence.
>ew local memories are allocated or ormal
parameters and the values o actual parameters
are copied into the ormal parameters.
>ew local memories are not allocated or ormal
parameters and the values o actual parameters are
not copied into the ormal parameters.
16. Define re(urion)
Recursion is a process #y which a unction calls itsel repeatedly until some speciied condition is met.
*ynta: unction 0
unction 0I
N
"n the a#ove unction the unction 0 is called themselves continuously.
11. W&"t "re t&e "$v"nt",e "n$ $i"$v"nt",e of re(urive fun(tion)
A$v"nt",e
"t is useul or #ranching processes.
"t is written with less num#er o statements.
Recursive unctions are eective.
Di"$v"nt",e
"t is diicult to thin2 the logic o a recursive unction.
"t is also diicult to de#ug the same.
&A
8/10/2019 2 Marks Final
17/21
1#. W&"t i " pointer)
Pointer is a varia#le which holds the address o another varia#le.
3 pointer is a derived data type in C.
*ynta: data9type varia#le9nameI
1%. W&"t "re t&e tep to initi"iBe " pointer v"ri"7e)
!eclare a pointer varia#le and note down the data9type.
!eclare a normal varia#le with same data9type.
"nitialiBe the normal varia#le and assign some value to it.
>ow, initialiBe pointer #y assigning the address o normal varia#le to pointer varia#le.
1*. W&"t i me"nt 74 nu pointer)
" the pointer does not have eact address to #e assigned when the >U66 value is assigned.
3 pointer that is assigned >U66 is called a null pointer.
1+. Define "rr"4 of pointer)
Pointer is a varia#le which holds the address o another varia#le.
3rray is a collection o similar data stored under a common name continuously in memory.
3rray name act as a pointer.
The array name always points the irst element o the array.
Unit +
1.Define tru(ture )
3 structure is a collection o heterogeneous data type in a se-uence.
3 structure is a collection o varia#le under a single name. *tructure is a user deined data type.
The 2eyword tru(tdeclares a structure to hold the details o data ields. These ields are called structure mem#ers.
#. W&"t i t&e nee$ for tru(ture $"t"t4pe)
Each element in an array must #e o the same data type. 3ll the data type canXt #e epressed in a single array. 1
have to declare dierent arrays or each data type. ut there will #e a #ig increase in source code. 8ence arrays cannot #
useul here. "t is oten desira#le to group data o dierent types and wor2 with that grouped data as one entity. The power t
accomplish this grouping with a new data type is called a structure.
%. Define tru(ture $e("r"tion. Or 2o3 to $e("re " tru(ture)
3 structure varia#le declaration is similar to declaration o varia#les o any other data types. The list o ields used to
declare structure varia#les are:
&. @eyword struct
'. *tructure name
&K
8/10/2019 2 Marks Final
18/21
(. 3 terminating semicolon
). 6ist o varia#le names seperated #y commas.
*. W&"t "re t&e rue to $e("re " tru(ture)
Rule9&: 3 structure must end with semicolon.
Rule9': Each structure element must #e terminated.
Rule9(: Usually, a structure appears at the top o the source program.
Rule9): The structure element must #e accessed #y structure varia#le with dot.0 operator.
+. Give t&e 4nt"! for tru(ture $e("r"tion.
*ynta Eample
struct structure9name
structWelement &I
structWelement 'I
LL
structWelement nI
None or more structure varia#lesI
-.2o3 tru(ture eement ("n 7e "((ee$ )
The process o using the structure mem#ers #y its corresponding structure varia#le in a C program is called accessin
structure mem#er. To access any mem#er o a structure, we use the mem#er access operator .0
*ynta structure9name . structure9mem#er I
/. Differenti"te "rr"4 "n$ tru(ture
S.No Stru(ture Arr"4
&3 structure is a collection o heterogeneous data
type in a se-uence.3n array is a collection o homogeneous data type.
' *tructure is a user deined data type. 3n array is a derived data type.
( *tructure must #e declared and deined. 3rray is a #uilt9in data type.
) 3 structure element can #e added i necessary. 3n array can #e increased or decreased.
+The structure mem#ers can #e accessed using
structure varia#les.
1e can access array li2e normal varia#le with its
position.
0. Define Union)
3 union is a collection o heterogeneous data type in a se-uence.
Union is a user deined data type used to stored data under uni-ue varia#le name at single memory location.
To declare a union data type,Union 2eyword is used. Union is similar to structure.
. Define union $e("r"tion. Or 2o3 to $e("re " union)
3 union varia#le declaration is similar to declaration o varia#les o any other data types.
&
struct #oo2
char title$+7%I
char author$+7%Ichar su#Gect$+7%I
int #oo29idIN #oo2&,#oo2'I
8/10/2019 2 Marks Final
19/21
The list o ields used to declare union varia#les are:
&. @eyword union
'. Union name
(. 3 terminating semicolon
). 6ist o varia#le names seperated #y commas.
16. Give t&e 4nt"! for union $e("r"tion.
*ynta Eample
union union9name
unionWelement &I
unionWelement 'I
LL
unionWelement nI
N one or more union varia#lesI
11. W&"t "re t&e rue to $e("re " union)
The ollowing rules should #e ollowed while declaring a union.
Rule9&: 3 union must end with semicolon.
Rule9': Each union element must #e terminated.
Rule9(: Usually, a union appears at the top o the source program.
Rule9): The union element must #e accessed #y union varia#le with dot.0 operator.
1#. 2o3 union eement ("n 7e "((ee$)
The process o using the union mem#ers #y its corresponding union varia#le in a C program is called accessing unio
mem#er. To access any mem#er o a union, we use the mem#er access operator .0
*ynta union9name . union9mem#er I
1%.W&"t "re t&e "$v"nt",e of union over tru(ture)
*aves space.
8elps to view a data item in two or more dierent ways.
8elps to #uild heterogeneous data structures.
Mem#ers o a union share the same memory.
The siBe o a union is the siBe o the largest mem#er.
1*.Differenti"te Union "n$ tru(ture.
UNION STRUCTURE
The 2eyword unionis used to deine a union. The 2eyword tru(tis used to deine a structure.
1hen a varia#le is associated with a union, the compiler 1hen a varia#le is associated with a structure, the compiler
&
union #oo2
char title$+7%Ichar author$+7%I
char su#Gect$+7%I
int #oo29idI
N #oo2&,#oo2'I
8/10/2019 2 Marks Final
20/21
allocates the memory #y considering the siBe o the largest
memory. *o, siBe o union is e-ual to the siBe o largest
mem#er.
allocates the memory or each mem#er. The siBe o structure
is greater or e-ual to the sum o siBes o its mem#ers. The
smaller mem#ers may end with unused stac2 #ytes.
Memory allocated is shared #y individual mem#ers o union. Each mem#er within a structure is assigned uni-ue storage
area o location.
1+. Define nete$ tru(ture)
" a structure contain more than one structure as its mem#ers is 2nown as nested structure.
E!"mpe
struct date
int date,month,yearI
Ndo#I
struct student
char name$&7%I
tru(t $"te $o7
Nstudent&I
1-.W&"t "re tor",e ("e)
*torage classes tell the compiler where to store a varia#le, how to store a varia#le, what is the initial value o th
varia#le and lie time o the varia#le.
*ynta storage9class data9type varia#le9nameI
There are ) types : 3utomatic , *tatic , Eternal and Register1/.W&"t i me"nt 74 (ope of " v"ri"7e)
The scope o a varia#le determines the area o a varia#le is actually availa#le or use.
The visi#ility reers to the accessi#ility o a varia#le rom memory.
The varia#les can #e classiied depending on the place o their declaration.
10. Comp"re o(" v"ri"7e "n$ ,o7" v"ri"7e.
&.6ocal varia#les :
6ocal varia#les are declared inside a particular unction or #loc2 o the program.
The local varia#les can #e accessed within the #loc2 or unction.
'.Dlo#al varia#les :
Dlo#al varia#les are declared outside o all unctions including main 0 unction.
The glo#al varia#les can #e accessed #y all the user deined unctions including main 0 unction.
1.W&"t "re prepro(eor $ire(tive)
Commands used in are called preprocessor directives and they #egin with 4 F 4 sym#ol and do not end with 4 I 4
'7
8/10/2019 2 Marks Final
21/21
Eample: F deine,
F include
#6. W&"t "re t&e t4pe of prepro(eor $ire(tive)
&. =ile "nclusion
'. Macro *u#stitution
(. Conditional "nclusion
'&