Re: Quick Help:'C' questions from an Electronic company
Marcel <[email protected]> Sat, 12 Feb 2005 14:05:58 -0800 (PST)
| Newsgroups | gmane.comp.programming.cppug |
|---|---|
| Message-ID | <[email protected]> |
1) x>>=1; is not a valid C expression.. 3) unsigned int a=6; int b= -20; is also not valid by the way, why do want that? some of the questions you may just run and see what happened.. the list is not here to do your homework --- khem metre <[email protected]> wrote: > > Hello friend , > following are the C questions asked in an electronic > > company. > Please answer the questions with description: > > > > > 1). What is the value of X after the execution of > follwing program > on a machine that uses 16 bit integers? > > int x=0x8000; > x>>=1; > > a) ox4000 b) 0xc000 c) 0x0 d) None of the > above > > 2). On a perticular machine a C compiler implements > 16 > bit integerts and 8 bit characters. > > int a[10]; > char *b; > int *c, *d; > > b=(char *) a; > c=a; > b=b+4; > d=(int *)b; > c++; > what are data items to which b and c are pointing > now? > > a) a[4] and a[1] > b) a[2] and a[1] > c) a[4] and a[2] > d) a[5] and a[2] > > 3) Which is the correct output for follwing > program:- > > unsigned int a=6; > int b= -20; > ( a + b > 6 ) ? puts(">6") : puts("<=6"); > > a) >6 > b) <=6 > c) >6 and <=6 > d) none of the above > > > 4) A program needs to use a value of PI (i.e. > 3.1400) > in calculation. > How would you declare value of PI using a macro? > Note that highest possible resolution is desired. > > > 5). following C code uses a keyword interrupt to > define an ISR . > comment on the code. > > interrupt double compute_area(radius) > double radius; > { > double area=PI * radius * radius; > return area; > } > > > 6) Each of the alphabets stand for one digit, in > the > following sum. Find the values for each of the > alphabets. Indicate the logic used. > > F O R T Y > + T E N > + T E N > ----------------------- > S I X T Y > ----------------------- > > 7) following are some valid instructions for a > hypothetical microcontroller > which result in loading the accumulator by 0. > Which of these is most efficient? > i. mov a,0 > ii. xor a,a > iii. mul a,0 > iv. sub a,a > > a) i > b) ii > c) iii > d) iv > > 8) Two programs develop 2 program modules a.c and > b.c independently > which are linked together. > > File- a.c contains following code:- > static char a, b; > main() > { > fcall(); > printf (" a=%d b=%d \n ", a , b); > } > > File- b.c contains following code:- > extern int a,b; > void fcall() > { > a=10; > b=20; > } > Which of the following is the likely output of the > program. > a) a=10 b=0 > b) a=10 b=20 > c) a=0 b=20 > d) None as the linker would indicate an error > > > 9) Which of the following expression evaluations > would > be most efficient? > i. a=a*10; > ii. a=a*8+a*2; > iii. a=a<<3 + a<<1; > iv. a=a<<3 + a+a; > > a) i > b) ii > c) iii > d) iv > > 10) int a,b,c; > long d; > Which of the following expressions evaluate the > result > with minimum > loss of resolution. > i. d=a/b*c; > ii. d=(long)a*c/b; > iii. d=(a/b)*c; > iv. d=(a*c)/b; > > a) ii > b) iv > c) ii and iv > d) i > > 11) Is the following piece of code incorrect ? If > incorrect rectify the errors. > > long percent (a,b) > long a,b; > { > long d; > d=(a*100)/b; > return d; > } > > main() > { > int marksob , per, total; > total=1400; > scanf( " enter the marks obtained ", marksob); > per=percent(marksob, total); > printf("percentage is %3d.%2d \n",per/100, per%100); > } > > 12) using vatiable a, give definations for > following:- > example :- 1) An integer > Answer: int a; > 2) A pointer to an integer > 3) an array of 10 integers > 4) An array of 10 pointers to integers > 5) A pointer to an array of 10 integers > 6) A pointer to a function that takes an integer as > an > argument and returns an integer > 7) An array of ten pointers to functions that take > an > integer argument & return an integer. > > 13) write a C function in a program to decide > whether the year is a leap year or not. > Note:- optimize the function for execution > time efficiency. > > > 14) A 100 Km long highway has 1 milestone after > every Km. > Total how many milestones are there? > > > === message truncated === __________________________________ Do you Yahoo!? Yahoo! Mail - Easier than ever with enhanced search. Learn more. http://info.mail.yahoo.com/mail_250 Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/cppug/ <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/