INTRODUCTION TO COMPPUTER PROGRAMMING

  • Upload
    maxi

  • View
    214

  • Download
    0

Embed Size (px)

Citation preview

  • 8/18/2019 INTRODUCTION TO COMPPUTER PROGRAMMING

    1/6

    DEC 2014 Q:1ai. scanf(“%u”,&x);ii. scanf(“%u”,&y);iii. unsigned int l=1;iv. unsigned int power=1;v. power=power*x;vi. l++;vii. wile(l!=y)

    viii. printf(“%u”,power);DEC 2014 Q:1b"i#erentiate $etween syntax and seantics wit an exeplary codeANSWER:

    SYNTAX SEMANTICS1 'yntax refers to foral rules goerning teconstruction of alid stateents in a language

    'eantics refers to te set of rules wic giete eaning of a stateent

    rrors due to syntax occur in a prograwen ruels of te prograing language areiolated or isused

    rrors due to seantics occur in a prograwen stateents are not eaningful

    'yntax is only concerned wit wat is

    linguistically and graatically correct

    'eantics reuires all ones prior -nowledge

    wic, and is far $eyond anyting wic islanguage speci.c/ 0ord order is te $asic principal of syntax,tose trying to understand wat is written usete syntactic cues of word order to elp giete sentence structure and eaning

    'eantics are an indiiduals own interpretationof te eaning of a sentence $ased on teirprior -nowledge 2erefore a sentence tatseeingly a-es no syntactic sense, can aeeaning wen using seantic cues

    3 45678  9nt a;  a=  in te a$oe code issing seicolon issyntax error

    456789nt a=,$=:,c;c=a$;in te a$oe code c=a$ is seantic error$ecause c is an int aria$le and assigned an

  • 8/18/2019 INTRODUCTION TO COMPPUTER PROGRAMMING

    2/6

    are declared in ain function printf(@n te su of two nu$ers is%d,result);return C;ABere, a,$ and result are glo$al aria$les wicare declared $efore te ain function

    DEC 2014 Q:2a"i#erence $etween arrays and structuresA!"#$

     Arrays Structures

    1. An array is a collection of related data elements of sametype.

    1. Structure can have elements of different types

    2. An array is a derived data type 2. A structure is a programmer-defined data type

    3. Any array behaves like a built-in data types. All wehave to do is to declare an array variable and use it.

    3. But in the case of structure first we have to design anddeclare a data structure before the variable of that typeare declared and used.

    DEC 2014 Q:2c

    0at is dynaic eory allocationD write down any two functions used for dynaic eoryallocarion in c languageDA!"#$:

    D%a&ic M#&'$% A(('ca)i' 2e process of allocating eory at runtie is -nown as dynaic eory allocation 8i$raryroutines -nown as eory anageent functions are used for allocating and freeing eoryduring execution of a progra 2ese functions are de.ned in stdli$

    *+c)i'

    D#!c$i,)i'

    alloc()

    allocates reuested siEe of $ytes and returns a oid pointer pointing to te .rst $yte ofte allocated space

    calloc() allocates space for an array of eleents, initialiEe te to Eero and ten return a oidpointer to te eory

    free releases preiously allocated eory

    realloc odify te siEe of preiously allocated space

    DEC 2014 Q:2-0rite a progra to reerse te strings stored in te following array of pointers to stringsFcar *sG H = ?

    2o err is uan,Iut to really ess tings up,Jne needs to -now KLL

    A ;A!"#$:oid ain()? car *sGH=? 2o err is uan, Iut to really ess tings up, Jne needs to -now KLL A; int i; for(i=C;i!;i++) xstrre(sGiH);

     for(i=C;i!;i++)

  • 8/18/2019 INTRODUCTION TO COMPPUTER PROGRAMMING

    3/6

     printf(@n%s,sGiH);Axstrre(car *)? car *tep1; car *tep; car *clear; int i,len,M; *clear=N@CN; len=strlen()O1; for(i=C,M=len;;i++,MOO) ? printf(@n $/ *(+i) is %c,*(+i)); *tep1=*(+i); *tep=*(+M); *(+i)=*clear; *(+M)=*clear; *(+i)=*tep; *(+M)=*tep1; * printf(@n i is %d, M is %d,i,M); * if((MOi)==1PPM==i) $rea-; printf(@n 5fter *(+i) is %c,*(+i)); AA

    DEC 2014 Q:0a"escri$e ow stac- is ipleented in a ig leel language in ters of a one diensional arrayA!"#$:'tatic ipleentation uses arrays to create stac- 9pleentation of stac- using arrays is a erysiple tecniue 2e priitie operations perfored on te stac- are as followsF/SF 2e process of adding (or inserting) a new eleent to te top of te stac- is called 7Q'Boperation 7using an eleent to a stac- will add te new eleent at te top 5fter eery pusoperation te top is increented $y one 9f te array is full and no new eleent can $eaccoodated, ten te stac- oer

  • 8/18/2019 INTRODUCTION TO COMPPUTER PROGRAMMING

    4/6

     

    D#c 2014 Q:04a0at is swappingD 0rite a progra to pass an array to a user de.ned functionA!"#$:'wapping of two aria$les refers to utually excanging te alues of te aria$les Qsually,tis is done wit te data in eory7SJS56 2J 75'' 5T 5SS5U 2J Q'S "R9T" RQTK29JTVinclude !stdioW

    Vinclude !conioWoid func(int aGH);oid ain()?int cGH=?, 33, , , /C, 1XA;func(c);getc();Aoid func(int aGH)?int 9,su; for(i=C;i!:;++i)?

      su+=aGiH;  Aprintf(“%d”,su);return C;A

    D#c 2014 Q:04b0at is function prototypeD xplain te di#erence $etween paasing arguents $y reference and$y alueA!"#$:5 function prototype or function interface is a declaration of a function tat speci.es tefunctionNs nae and type signature (paraeter types, and return type), $ut oits te function

    $ody

    Pass by Value Pass by Reference

    7asses an arguent $y alue 7asses an arguent $y reference

     2e procedure code does not ae any accessto te underlying eleent in te calling code

     2e procedure code gies a direct reference tote prograing eleent in te calling code

    9n tis, you are sending a copy of te data 9n tis, you are passing te eory address ofte data tat is stored

    Kanges does not a#ect te actual alue Kanges to te alue e#ect te original data

  • 8/18/2019 INTRODUCTION TO COMPPUTER PROGRAMMING

    5/6

    DEC 2014 Q:04c"e.ne te followingF

     

    /OINTER O/ERATORS:

     2ere are two pointers operation in c

     

    INCREMENT AND DECREAMENT O/ERATORS:

    9ncreent and decreent operators are unary operators tat add or su$tract one fro teiroperand, respectiely 2e increent operator increases te alue of its operand $y 1, te increent operator is writtenas ++ 2e decreent operator decreases te alue of its operand $y 1, te decreent operator iswritten as OO45678 KJ"Fint x;int y; 9ncreent operatorsx = 1;y = ++x; x is now , y is also y = x++; x is now , y is

    "ecreent operatorsx = ;y = xOO; x is now , y is y = OOx; x is now 1, y is also 1

     

    !i#'3 O/ERATORS:

     2e unary operator siEeof generates te siEe of a aria$le or datatype, easured in te nu$erof car siEe storage units reuired for te typeS%)asiEeof( type )

     5+(% 2016 Q:4Tae and descri$e a tleast any two pro$le analysis tecniuesD 5lso gie exaples to explainyour answerA!"#$:7ro$le analysis can $e de.ned as dissecting and torougly studying a pro$le wit te

    o$Mectie to understand ow te pro$le eerged and ow it grew to its current proportions 2ere are $asic steps in soling a pro$leF1 "e.ne te 7ro$le "eterine te Soot Kause(s) of te 7ro$le "eelop 5lternatie 'olutions/ 'elect a 'olution39pleent te 'olution: aluate te Jutcoe

    D#7# )8# /$'b(#& 2e .rst step, identifying te pro$le, is a $road reiew of te current situation Y a .ttingtogeter of inforation, li-e pieces of a puEEle 9n tis .rst stage, a group identi.es anddiscusses te syptos and scope of te pro$le 2at is, it deterines wat “urts,” tedegree to wic te syptos are sared, and te urgency of relieing te syptos roups

    O,#$a)'$ O,#$a)'$ Na /+$,'!#

    * >alue at Jperator ies >alue stored at 7articular address

    & 5ddress Jperator ies 5ddress of >aria$le

  • 8/18/2019 INTRODUCTION TO COMPPUTER PROGRAMMING

    6/6

    use tools suc as $rainstoring, interiewing, and copleting uestionnaires to gater tisinforation

    D#)#$&i# )8# R'') Ca+!#9! '3 )8# /$'b(#&Jnce you recogniEe te syptos and ae tentatiely de.ned te pro$le, your group can$egin to collect inforation a$out te nature of te pro$le 5t tis step, you ay use toolssuc as te Ris$one diagra, or 7areto analysis to elp you organiEe tis inforation and Eeroin on underlying causes of te pro$le 9n tis way, you deterine te root causes of tepro$le

    EXAM/LE:ien te scores for te two departental uiEEes, two acine proMects, .nal exa, andteacerNs ealuation, write a progra tat will copute for te .nal grade $ased on te followingcoputationF 3C% 5erage of two departental uiEEes+13% aerage of acine proMects+C% Rinal exa+3% 2eacerNs ealuation