Showing posts with label C++. Show all posts
Showing posts with label C++. Show all posts

Tuesday, October 29, 2013

Programming (C, C++ ...) 02

11. Assume that we have constructor functions for both base class and derived class. Now consider the declaration in main( ). Base * P = new Derived; in what sequence will the constructor be called? [Paper III June 2012]
(A) Derived class constructor followed by Base class constructor.
(B) Base class constructor followed by derived class constructor.
(C) Base class constructor will not be called.
(D) Derived class constructor will not be called.

12. printf(“%c”, 100); [Paper II June 2012]
(A) prints 100
(B) prints ASCII equivalent of 100
(C) prints garbage
(D) none of the above

13. Which API is used to draw a circle ? [Paper II December 2012]
(A) Circle( )                 (B) Ellipse( )
(C) RoundRect( )         (D) Pie( )

14. Which of the following are two special functions that are meant for handling exception, that occur during exception handling itself? [Paper II December 2012]
(A) void terminate ( ) and void unexpected ( )
(B) Non void terminate ( ) and void unexpected ( )
(C) void terminate ( ) and non void unexpected ( )
(D) Non void terminate ( ) and non void unexpected ( )

15. Match the following with respect to C++ data types: [Paper II December 2012]
a. User defined type 1. Qualifier
b. Built in type 2. Union
c. Derived type 3. Void
d. Long double 4. Pointer
Code :
       a b c d
(A) 2 3 4 1
(B) 3 1 4 2
(C) 4 1 2 3
(D) 3 4 1 2

16. Enumeration is a process of [Paper II December 2012]
(A) Declaring a set of numbers
(B) Sorting a list of strings
(C) Assigning a legal values possible for a variable
(D) Sequencing a list of operators

17. Which of the following mode declaration is used in C++ to open a file for input?
[Paper II December 2012]
(A) ios : : app
(B) in : : ios
(C) ios : : file
(D) ios : : in

18. What is the result of the following expression? [Paper II December 2012]
(1 & 2) + (3 & 4)
(A) 1
(B) 3
(C) 2
(D) 0


SOLUTIONS

11. B
Here A derived class object is created first and then assigned to a base class pointer. Whenever a derived class object is created, the base class constructor gets called first and then the derived class constructor.

12. B

13. B

14. A
The visual C++ Standard requires that unexpected() is called when a function throws an exception that is not on its throw list.
The terminate( ) function is used with visual C++ exception handling and is called in the following cases:

  • A matching catch handler cannot be found for a thrown C++ exception.
  • An exception is thrown by a destructor function during stack unwind.
  • The stack is corrupted after throwing an exception.

Both the functions does not return anything.

15. A

16. C
An enum is a user-defined type consisting of a set of named constants called enumerators. The colors of the rainbow would be mapped like this.:
              enum rainbowcolors { red,  orange, yellow, green,  blue, indigo, violet)  }
Now internally, the compiler will use an int to hold these and if no values are supplied, red will be 0, orange is 1 etc.

17. D
In order to open a file with a stream object we use its member function open():
          open (filename, mode);
Where filename is a null-terminated character sequence of type const char * (the same type that string literals have) representing the name of the file to be opened, and mode is an optional parameter with a combination of the following flags:

  • ios::in    Open for input operations.
  • ios::out    Open for output operations.
  • ios::binary  Open in binary mode.
  • ios::ate    Set the initial position at the end of the file. If this flag is not set to any value, the initial position is the beginning of the file.
  • ios::app    All output operations are performed at the end of the file, appending the content to the current content of the file. This flag can only be used in streams open for output-only operations.
  • ios::trunc    If the file opened for output operations already existed before, its previous content is deleted and replaced by the new one.

18. D
& represents bitwise AND. Converting the given values in the expression to 4 bit binary we have:
(1 & 2) + (3 & 4) = (0001 & 0010) + (0011 & 0100)
                            = (0000) + (0000)
                            = 0 + 0
                            = 0

Saturday, August 3, 2013

Programming (C, C++ ...) 01

01. When a programming Language has the capacity to produce new datatype, it is called as,
[Paper III December 2012]
(A) Overloaded Language
(B) Extensible Language
(C) Encapsulated Language
(D) Abstraction Language                  

02. The Default Parameter Passing Mechanism is called as       [Paper III December 2012]
(A) Call by Value
(B) Call by Reference
(C) Call by Address
(D) Call by Name

03. Functions defined with class name are called as                   [Paper III December 2012]
(A) Inline function            (B) Friend function
(C) Constructor               (D) Static function

04. Assume that we have constructor functions for both base class and derived class. Now consider the declaration in main( ). Base * P = New Derived; in what sequence will the constructor be called? 
[Paper III June 2012]
(A) Derived class constructor followed by Base class constructor.
(B) Base class constructor followed by derived class constructor.
(C) Base class constructor will not be called.
(D) Derived class constructor will not be called. 

05. Consider the program below in a hypothetical programming language which allows global variables and a choice of static or dynamic scoping                  [Paper III December 2012]
int i;
program Main( )
{
       i = 10;
       call f ( );
}
procedure f( )
{
        int i = 20;
        call g ( );
}
procedure g( )
{
       print i;
}
Let x be the value printed under static scoping and y be the value printed under dynamic scoping. Then x and y are
(A) x = 10, y = 20
(B) x = 20, y = 10
(C) x = 20, y = 20
(D) x = 10, y = 10

06. printf(“%c”, 100);                                  [Paper II June 2012]
(A) prints 100
(B) prints ASCII equivalent of 100
(C) prints garbage
(D) none of the above

07. X – = Y + 1 means                               [Paper III December 2012]
(A) X = X – Y + 1
(B) X = –X – Y – 1
(C) X = –X + Y + 1
(D) X = X – Y – 1

08. The _______ memory allocation function modifies the previous allocated space. 
[Paper III June 2012]
(A) calloc( )                 (B) free( )
(C) malloc( )                (D) realloc( )

09. The mechanism that binds code and data together and keeps them secure from outside world is known as                  .           [Paper III June 2012]
(A) Abstraction           (B) Inheritance
(C) Encapsulation       (D) Polymorphism

10. Match the following with respect to java.util.* class methods:     [Paper III June 2012]
(a) Bit Set                    (i) Time zone getTimezone( )
(b) Calendar                (ii) int hashcode( )
(c) Time zone              (iii) int nextInt( )
(d) Random                 (iv) void setID(String tzName)
(a)        (b)        (c)        (d)
(A)       (ii)        (i)         (iv)       (iii)
(B)       (iii)       (iv)        (i)         (ii)
(C)       (iv)       (iii)        (ii)        (i)
(D)       (ii)        (i)         (iii)       (iv)



SOLUTIONS
1. B

2. A

3. C

4.

5. D
Whatever be the scoping, the i declared inside the method f() is not accessible outside. So when we say i from g(), it refers to global i. So under both cases, 10 is printed

6. B

7. D
X - = Y + 1    =>     X = X - (Y+1)    =>     X = X - Y - 1

8. D
malloc allocates the specified number of bytes
realloc increases or decrease the size of the specified block of memory. Reallocates it if needed
calloc allocates the specified number of bytes and initializes them to zero

free         releases the specified block of memory back to the system

9. C

10. A
The exact match is
(a) Bit Set                    (ii) int hashcode( )
(b) Calendar                (i) Time zone getTimezone( )
(c) Time zone               (iv) void setID(String tzName)
(d) Random                 (iii) int nextInt( )