Quick Google Search

QUESTIONS OF C OF IBM, AMDOCS, GOOGLE, FACEBOOK, VMWARE, DELL, SYNTEL, HSBC, REDHAT

#######################################################################
                         2.QUESTIONS
#######################################################################

1. Base class has some virtual method and derived class has a method with the same name. If we initialize the base class pointer with derived object; calling of that virtual method will result in which method being called?
a. Base method b. Derived method.
c. Error d. None of these


2. Given below are two sets of statements:(a) & (b). Select the correct observation:

a> const char *p="Hello"; p="World";
b> char * const p="Hello"; p[1]='P';

A. Both a & b are correct since non-const data/pointer is being changed in both cases.
B. Both a & b are wrong since const data/pointer cannot be changed once assigned.
C. a is correct, b is wrong.
D. a is wrong, b is correct.


3. void main ()
{
"Bunka"[2]='P';
}

Select the correct statement:
A. Error: lvalue required
B. Error: A string literal is a const char * and hence cannot be modified directly.
C. A string literal has the data type char * and hence cannot be modified.
D. The code compiles but memory access error at run-time.


4. Select all the correct statements about "Abstraction"
A. Assumes essential characteristics of an object to distinguish it from other kinds of objects.
B. Provides a simplified view of the object.
C. It separates the implementation from its interface.
D. It is the enforcement of the type class of an object.

5. The behavior of a class is decided by
A. Data members. B. Methods. C. Access permissions. D. All of the above.

6. Which statement(s) is/are true about "Static Typing"?
A. Refers to Types declared at compile time.
B. More efficient and reliable than dynamic typing.
C. Can be used to implement polymorphism.
D. Refers to all static data/methods in your classes.

7. Which statements(s) is/are true about Dynamic binding?
A. The correct function to call is resolved at run-time.
B. These functions are statically typed.
C. These functions are dynamically typed.
D. Refers to all dynamically allocated data in your classes.

8. Reusability of objects is achieved by
A. Inheritance. B. Aggregation. C. Polymorphism. D. All of the above.

9. Which statements(s) is/are true about "Hierarchy" of objects?
A. It is an ordering of abstractions.
B. It refers to "is a " relationship expressed by inheritance.
C. It refers to "has a" relationship expressed by aggregation.
D. It refers to access permissions on the aggregated object within an object.

10. What are "Generic classes"? (Select all that are correct)
A. A universal base class to cater to a wide range of derived classes.
B. A parameterized class, which is reusable across, types.
C. Used where implementation and behavior is independent of type.
D. Also known as abstract classes.

11. A language is "Object Base" if (Select all that are correct)
A. It supports abstraction. B. It has a concept of class.
C. It provides direct support for inheritance. D. All of the above.

12. "Object Persistence" covers which of the following (Select all that are correct)
A. Global variables & heap items. B. Object data storage.
C. Object type storage. D. All of the above.

13. Which statement(s) is/are true about shared inheritance?
A. All base classes are by default example of shared inheritance.
B. In multiple inheritances the derived classes share a single instance of the Base Class.
C. The base class is declared dynamically & there can be only one instance of it.
D. It allows distributed objects to share remote object and treat it as their own.


14. void f (int y)
{
struct s *ptr;
ptr = malloc (size of (struct)+99*size of (int));
}
struct s
{
int i;
float p;
};
when free (ptr) is executed, what will happen?

15. . Using pointer, changing A to B and B to A is swapping the function using two addresses and one temporary variable. a, b are address, t is temporary variable. How function look like?

16. Write a c program to find whether a stack is progressing in forward or reverse direction.

17. What is the output of the following program?
void main ()
{
char *ptr1="DCM0DAT\0ASYSTEMS";
clrscr ();
printf ("%d %s ", strlen (ptr1),ptr1);
printf ("%d %s ",strlen (ptr1+8),ptr1+8);
getch ();
}

18. How do you declare an array of N pointers to functions returning pointers to functions returning pointers to characters?

19. void main ()
{
char *s []={“dharma", "hewlett-packard", "siemens", "ibm"};
char **p;
p=s;
printf ("%s", ++*p);
printf ("%s", *p++);
printf ("%s", ++*p);
}

20. Which holds true for the following statement
class c: public A, public B
a) 2 member in class A, B should not have same name
b) 2 member in class A, C should not have same name
c) both
d) none

21. Given the following c program
func (int *i, int*j)
{*i=*i * *i;
*j=*j* *j;
}
main ()
{ int i = 5, j = 2;
func (&i, &j);
printf ("%d %d", i, j);
}
What is the output?

22. For the following C program
void insert (key, r)
type key key, data array r;
{extern int n;
if (n>=max) /*error table if full */
else r [n++]. k=key;
}
This on executing, enables a
a) Basic sequential search b) Binary search c) Interpolation search d) None

23. f (char *p)
{
p [0]? f (++p): 1;
printf ("%c", *p);
}
if call that function with f (Aabcd) what is the output??

24 In a class only declaration of the function is there but definition is not there then what is that function ?

25 What is the use of global static variable in C?

#######################################################################
                              2. ANSWERS
#######################################################################

1 (b)
15 swap (int *, int *, int)
18 The first part of this question can be answered in at least three ways:

a). char *(*(*a [N]) ())();

b) Build the declaration up incrementally, using typedefs:
typedef char *pc; /* pointer to char */
typedef pc fpc (); /* function returning pointer to char */
typedef fpc *pfpc; /* pointer to above */
typedef pfpc fpfpc (); /* function returning... */
typedef fpfpc *pfpfpc; /* pointer to... */
pfpfpc a [N]; /* array of... */

c) Use the cdecl program, which turns English into C and vice versa:
cdecl> declare a as array of pointer to function returning pointer to function returning pointer to char
char *(*(*a []) ())()
cdecl can also explain complicated declarations, help with casts, and indicate which set of parentheses the arguments go in (for complicated function definitions, like the one above).
Any good book on C should explain how to read these complicated C declarations "inside out" to understand them ("declaration mimics use").
The pointer-to-function declarations in the examples above have not included parameter type information. When the parameters have complicated types, declarations can *really* get messy. (Modern versions of cdecl can help here, too.)

19. "harma" (p->add (dharma) && (*p)->harma)
"harma" (after printing, p->add (hewlett-packard) &&(*p)->harma)
"ewlett-packard"
20. (a)
23. dcbaA (Just reversing the string)
24. virtual function

No comments:

Popular Posts