Re: [C_Programming] Quick Help:'C' questions from an Electronic company
Ranjeet Gupta <ranjeet.gupta-NjGUCoSd/[email protected]> Mon, 28 Mar 2005 11:01:31 +0530
| Newsgroups | gmane.comp.lang.c.general,gmane.comp.programming.cppug |
|---|---|
| Organization | Optical Fusion Software Services (I) Pvt Ltd |
| Message-ID | <[email protected]> |
Comment Below !! (Where ever I felt it is neccessary to comment,
leaving rest for you to try.)!!
Regards
Ranjeet
khem metre 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
ans: a) ox4000
>
>
> 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]
I dont find any of the option in my opinion: the correct answer will be
a[1], a[1]
>
>
> 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
Answer will be a) i.e
over above you have the unsigned and the signed int
now signed int + ungined int = unsigned int
Let take the above case :
unsigned int (6) + signed int(-20) = unsigned int (4294967282)
Now which is definetly greater then 6 so condition satisfy.
Now you must be amazed why we get the above value.
6 + (-20) = -14
Now as the compiler takes the above case: signed int + ungined int
= unsigned int
-14 is round of into its range : like below
2 power 32 (Unsigned Int) = (4294967296 - 14) = 4294967282
No Doubt If The Compiler would have taken this as the documented thing:
"signed int + ungined int = signed int" then your value will be -14
anyway the motive behind this question to know weather you know
this point : signed int + ungined int = unsigned int
ASFAIK: unsigned char + signed char = signed int]
unsigned char + signed short = signed int
signed char + unsigned short = signed int
unsigned char + signed int = signed int
signed char + unsigned int = unsigned int
unsigned short + signed int = signed int
signed short + unsigned int = unsigned int
Please correct me others If I am worng.
>
>
>
> 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.
#define PI 22 / 7
> 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
>
answer: d)
>
> 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
Answer c) iii iii. a=a<<3 + a<<1;
>
>
> 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
answer a) ii. d=(long)a*c/b;
>
>
> 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?
>
>
> 15) Convert following C program fragment into any of
> the assembly languages you know:
> Note that a and b are character variables,
> and c is an integer variable.
> if (a)
> d++;
> else
> if (c)
> d - -;
> else
> d=0;
>
>
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Take Yahoo! Mail with you! Get it on your mobile phone.
> http://mobile.yahoo.com/maildemo
>
> *Yahoo! Groups Sponsor*
> ADVERTISEMENT
>
>
> ------------------------------------------------------------------------
> *Yahoo! Groups Links*
>
> * To visit your group on the web, go to:
> http://groups.yahoo.com/group/C_Programming/
>
> * To unsubscribe from this group, send an email to:
> C_Programming-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org
> <mailto:C_Programming-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org?subject=Unsubscribe>
>
> * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service <http://docs.yahoo.com/info/terms/>.
>
>