C Programming and Problem Solving Questions and Answers 171 to 180

C Programming and Problem Solving

Questions 171 to 180



171.
If  a=Oxaa and   b=a<<1 then
(a)  b=2a       (b)  b=a/2            (c)  a=b-1          (d)  b=a-1          (e)  b=a.
172.
Which of the following operator(s) has/have right to left associativity?
(a)  ++          (b)  – –                (c)  += 
(d)  Both (a) and (b) above         (e)  All (a), (b) and (c) above.
173.
With the following declaration , the correct answer is
enum rgb{red=-1, green, blue};
(a)   red= -1   green= -2   blue= -3
(b)   red= -1   green= 1     blue= 2
(c)   red= -1   green= 0     blue= 1
(d)   red= -1   green= 2     blue= 3
(e)   All the above alternatives are illegal declarations.
174.
What is the return value of the following function if the function is called as int value = fun(10);      
       int fun(int n)
       {
              if( n = = 1 ||  n = =  2)  return 0;
                   else   return( n-1 + fun(n-2) );
       }
(a)  20    (b)  26     (c)  22           (d)  24   (e)  0.
175.
Which of the following is not a key word in ‘C’?
(a)  void (b)  getchar     (c)  sizeof         (d)  short           (e)  volatile.
176.
Consider the following code:
       struct account {
                     int acno;
       }svar, *pv = &svar;
       then the acno can be accessed by
(a)  svar.acno       (b)  pv->acno            (c)  (*pv).acno   (d)  a & b & c    (e)  (a) & (b) only.
177.
Trace out the correct outcome of the following program:
void fun(char *s1, char *s2)
       {
              while(*s2)    *s1++ = *s2++;
              *s1 = ‘\0’;
       }
       void main()
       {
              char s2[]= “lion”,  s1[] = “monkey”;
              fun(s2, s1);
              puts(s2);
       }     
(a)  lion  (b)  lion monkey         (c)  monkey  (d)  null        (e)  Syntax error.
178.
While working with the binary streams for ‘C’ I/O file operations
(a)   Only the binary values can be read and can be written
(b)   No Character translation takes place
(c)   Character translation takes place
(d)   Number of characters written (read) are not same as the number that is stored on the external device
(e)   Both (a) and (b) above.
179.
The function islower (char) checks whether a character is in lower case or not and hence it should return
(a)   The character in lower case
(b)   The character itself
(c)   Nothing
(d)   -1, 0, or 1
(e)   0 or 1.
180.
The function sprintf( ) works like printf( ), but operates on
(a)  strings    (b)  data in a file               (c)  stderr         
(d)  stdin (e)  standard output device.

Answers

171.
Answer : (a)
Reason:  Because whatsoever the value of a may be the statement b = a<<1; shifts the bits of a towards left by one position. Hence it is same a multiplying the number (a) by 2
172.
Answer : (e)
Reason:  Because all these operators ( ++ -- ++= )are having the same associativity.
173.
Answer : (c)
Reason:  Because in enum declaration all the enum members are going to be initialized by a default of zero for first element and plus one to previous for the remaining all. And if the first element is assigned a value explicitly( red = -1 in these case ) with some integer value then the remaining all are going to be initialized with plus one with the previous element. And hence green = 0, blue =1
174.
Answer : (d)
Reason:  Because it is 9+7+5+3+0, where 9+7+5+3 for else return (n-1 + fun (n-2)); and
+0 for if (n = = 1 || n = = 2) return 0;
175.
Answer : (b)
Reason:  Because getchar [getchar ()] is a name of the predefined unformatted character input function and the remaining all are the key words.
176.
Answer : (d)
Reason:  Because all the ways are valid for accessing the members of a structure variable (svar) pointed by pointer (pv)
svar.acno              pv->acno                (*pv).acno
177.
Answer : (c)
Reason:  Because the following given code
void fun(char *s1, char *s2)
       {
       while(*s2) *s1++ = *s2++;
       *s1 = ‘\0’;
       }
copies the contents of s2 to s1 string and the call was made as
fun (s2, s1); where s1 = “monkey”
and the display was called for s2 as puts(s2 )
178.
Answer : (b)
Reason:  Because according to the definition of the binary files while working with the binary files no character translation takes place
179.
Answer : (e)
Reason:  Because the prototype of the function islower () is int islower (char); Hence it returns 1 for true (if char is a lower case character) and 0 for false (if not)
180.
Answer : (a)
Reason:  Because according to the definition of sprintf (), it works with the strings as printing the values in the string instead of console



<< Prev 1...  2...  3...  4...  5...  6...  7...  8...  9...  10...  11... 12...  13...  14...  15...  16...  17...  18...  19...  20...  21...  22...  23...  24...  25...  26...  27...  28...  29...  30...  31...  32...  33...  34...  35...  36...  Next >>


No comments :

What you think about these Questions and Answers ? Let me know in comments.

Post a Comment