News Ticker

Menu

Browsing "Older Posts"

Browsing Category "C-Programming"

UpWork (oDesk) & Elance C Programming Test Question & Answers

July 03, 2015 / No Comments
UpWork (oDesk) & Elance C Programming Test Question & Answers are really very important to pass UpWork & Elance test. You will get top score at this skill test exam. If you found any problem or wrong answer please inform me via contact or comments. We will try to solve it in short. This test is extremely valuable to acquire knowledge of C Programming. Lets Start test.


Ques : Which of the following statements will result in a compilation error?
Ans  :  int n=5, x; x= ++n++;
        int n=5, x; x= (n+1)++;
        int n=5, x=6; x= (n+x)++;


Ques : Which of the following statements are correct for the keyword register?
Ans  : It requests that the variable be kept in the CPU register for maximum speed
       It does not guarantee that the variable value is kept in CPU register for maximum speed

Ques : Which is/are the type/s of memory allocation that needs/need the programmer to take care of memory management?
Ans  : Dynamic memory allocation
       Memory allocation on stack

Ques : Given the array:

int num[3][4]= {
                    {3,6,9,12},
                    {15,25,30,35},
                    {66,77,88,99}
                    };
what would be the output of *(*(num+1)+1)+1?
Ans  : 26

Ques : Given the array:

int num[3][4]=
{
{3,6,9,12},
{15,25,30,35},
{66,77,88,99}
};

what would be the output of *(*(num+1))?
Ans  : 15

Ques : What would be printed on the standard output as a result of the following code snippet?

main()
{
        int i=5;
        char option = 5;
        switch(option)
        {
                case '5':
                                printf("case : 1 \n");
                                break;
                case i:
                                printf("case : 2 \n");
                                break;
                default:
                                printf("case : 3 \n");
                                break;
        }
        return 0;
}
Ans  : Result in compilation error

Ques : What is the return value in case a file is not opened successfully by using fopen()?
Ans  : NULL

Ques : What will be the output of following code?

int main()
   {
      int i;
      i = 0;
      for (i = 1; i <2 b="" i="">
      {
          i++;
          printf( "%d", i );
          continue;
          printf( "%d", i );
      }
      return 0;
   }
Ans  : 2

Ques : What would be printed on the standard output as a result of the following code snippet?

char *str1 = "Hello World";
strcat(str1, '!');
printf("%s", str1);
Ans  : The code snippet will throw a compilation error

Ques : Given the following array:

int a[8] = {1,2,3,4,5,6,7,0};
what would be the output of
        printf("%d",a[4]); ?
Ans  : 5

Ques : In order to read structures/records from a file, which function will you use?
Ans  :  fscanf()

Ques :  An array is defined with the following statement in a file, file1.c

        int a[ ] = { 1, 2, 3, 4, 5, 6 };

In another file, file2.c, the following code snippet is written to use the array a:

extern int a[];
int size = sizeof(a);

What is wrong with the above code snippet?
Ans  : An extern array of unspecified size is an incomplete type. The size of the operator during compile time is unable to learn the size of an array that is defined in another file

Ques : What would be printed on the standard output as a result of the following code snippet?

main()
{
        char *s="Hello World";
        char s1[20], s2[20];
        int len = sscanf(s,"%s",s1);
        printf("%s : %d", s1, len);
}
Ans  : Hello : 1

Ques :  Suppose there is a file a.dat which has to be opened in the read mode using the FILE pointer ptr1, what will be the correct syntax?
Ans  :  ptr1 = fopen("a.dat","r");

Ques : Given the following array:
     
char books[][40]={
                         "The Little World of Don Camillo",
                         "To Kill a Mockingbird",
                         "My Family and Other Animals",
                         "Birds, Beasts and Relatives"
                         };
what would be the output of printf("%s",books[3]);?
Ans  : Birds, Beasts and Relatives

Ques : What would be printed on the standard output as a result of the following code snippet?

void main()
{
    unsigned char a=25;
    a = ~a;
    signed char b = 25;
    b = ~b;
    printf("%d %d ", a, b);
}
Ans  : 230 -26

Ques : What will be printed on the standard output as a result of the following code snippet?

void main()
{
        int num1 = 30, num2 = 4;
        float result;
        result = (float)(num1/num2);
        printf("%.2f", result);
        return 0;
}
Ans  : 7.00

Ques : Which of the following is/are the correct signature/s of main with command line arguments?
Ans  :  int main(int argc, char *argv[])

Ques : From which of the following loop or conditional constructs, is "break" used for an early exit?
Ans  :  All of the above

Ques : Given the operators:

1) *
2) /
3) %

What would be the order of precedence?
Ans  : 1 and 2 have the same precedence, 3 is of lower precedence

Ques : Which of the following declarations of structures is/are valid?

        1)
                struct node {
                int count;
                char *word;
                struct node next;
                }Node;
        2)
                struct node {
                int count;
                char *word;
                struct node *next;
                }Node;
        3)
                struct node {
                int count;
                char *word;
                union u1 {
                        int n1;
                        float f1;
                }U;
                }Node;
Ans  : 1,2,3

Ques : What would be printed on the standard output as a result of the following code snippet?

main()
{
        int n=5, x;
        x = n++;
        printf("%d ", x);
        x = ++n;
        printf("%d ", x++);
        printf("%d", x);
        return 0;
}
Ans  : 5 7 8

Ques : In which area of memory are static variables allocated?
Ans  :   heap

Ques : Read the statement below:

extern int a;

Which of the following statement/s pertaining to the above statement is/are correct?
Ans  :  Brings the scope of the variable defined outside the file to this file

Ques : What would be printed on the standard output as a result of the following code snippet?

main()
{
char *pmessage = "asdfgh";
*pmessage++;
printf("%s", pmessage);
return 0;
}
Ans  : sdfgh

Ques :  Which function returns the current pointer position within a file?
Ans  : ftell()

Ques : Which of the following is a function for formatting data in memory?
Ans  : sprintf()

Ques : Which function allocates memory and initializes elements to 0?
Ans  :   calloc()

Ques : Is the following statement correct? If not, why not? If yes, what is the size of the array?

int array[][3] = { {1,2}, {2,3}, {3,4,2} };
Ans  : Yes, the size is three columns by two rows

Ques : Which of the following sets of conversion statements may result in the loss of data?
Ans  :    int i; float f; i=f; f=i;

Ques : Consider the following code.

int i = 4, *j, *k;

Which one of the following statements will result in Compilation error?
Ans  : j = j * 2;

Ques : By which file function you can position the file pointer in accordance with the current position?
Ans  : fseek()

Ques : What will be printed on the standard output as a result of the following code snippet?

void main()
{
        int arr[][2] = {1,2,3,4,5,6};
        printf("%d",arr[2][1]);
}
Ans  : 6

Ques : Which function will you use to position the file pointer at the beginning of the file?
Ans  : rewind()

Ques : Which header file are methods(or macros) isalpha(), islower() a part of?
Ans  :  ctype.h

Ques : What will be printed on the standard output as a result of the following code snippet?

void main()
{
    int i,j,k;
    i=4;
    j=30;
    k=0;
    k=j++/i++;
    ++k;
    printf("%d %d %d",i,j,k);
}
Ans  :  5 31 8

Ques :  What would be printed on the standard output as a result of the following code snippet?

main()
{
enum {red, green, blue = 6, white};
printf("%d %d %d %d", red, green, blue, white);
return 0;
}
Ans  :  0 1 6 7

Ques : What would be printed on the standard output as a result of the following code snippet?

main()
{
    int a[5] = {1,4,5,6,9};
    printf("%d\t", *a);    //Line 1
    printf("%d", *++a);    //Line 2
return 0;
}
Ans  : Compilation Error in "Line 2"

Ques : Which of the following standard functions is used to close a file?
Ans  :  fclose()

Ques : Identify the incorrect statement.
Ans  : Memory is reserved when a structure label is defined

Ques : Which of the following comparison statements will be true if an integer is 16 bits and a long is 32 bits on a machine?
Ans  : -1L > 1U

Ques :  Which of the following is the correct way of initializing a two-dimensional array?
Ans  :  char str[2][4]={ {'a','b','c','\0'}, {'d','e','f','\0'} };

Ques :   Which function will you use to write a formatted output to the file?
Ans  :  fprintf()

Ques : What would be printed on the standard output as a result of the following code snippet?

main()
{
        char option = 5;
        switch(option)
        {
                case '5':
                                printf("case : 1 \n");
                                break;
                case 5:
                                printf("case : 2 \n");
                                break;
                default:
                                printf("case : 3 \n");
                                break;
        }
        return 0;
}
Ans  : case : 2

Ques : What would be printed on the standard output as a result of the following code snippet?

#define func(t, a, b) { t temp; temp=a; a=b; b=temp; }
main()
{
        int a=3, b=4;
        float c=4.5, d = 5.99;
        func(int, a, b);
        func(float, c, d);
        printf("%d %d ", a, b);
        printf("%.2f %.2f\n", c, d);
}
Ans  : 4 3 5.99 4.50

Ques : What would be printed on the standard output as a result of the following code snippet?

main()
{
        void addup (int b);
                addup(b);
        return 0;
}
int b = 5;
void addup (int b)
{
        static int v1;
        v1 = v1+b;
        printf("%d ", v1);
}
Ans  : Will result in Compilation Error

Ques : Given the following array declaration:

       int a[2][3][4];
what would be the number of elements in array a?
Ans  : 24

Ques : Which file header is to be included for file handling in a C program?
Ans  : stdio.h

Ques : What is the return type of the following function declaration?

func(char c);
Ans  : undefined

Ques : What is the function to concatenate two strings?
Ans  :      strcat()

Ques : Which of the following statements is valid and correct?
Ans  : char amessage[] = "lmnop"; amessage++;

Ques : Which of the following is not a valid mode for opening a file?
Ans  : i

Ques : Given the following array:

        char books[][40]={
                         "The Little World of Don Camillo",
                         "To Kill a Mockingbird",
                         "My Family and Other Animals",
                         "Birds, Beasts and Relatives"
                          };
what would be the output of printf("%c",books[2][5]);?
Ans  : m

Ques : What will be printed on the standard output as a result of the following code snippet?

void main()
{
        char arr[] = {'R','A','M','\0'};
        printf("%d",strlen(arr));
}
Ans  : 3

Ques : Which function will convert a string into a double precision quantity?
Ans  : atof()

Ques : Which of the following is not a type of operator ?

Ans  : Ternary

Ques : The declaration int *(*p)[10] indicates:
Ans  :  p is a pointer to an array of integer pointers

Ques : What is the output of the following program ?

main()
{

int u = 1, v = 3;
printf("%d %d",u,v);
funct1(&u,&v);
printf(" %d %d\n",u,v);
}

void funct1(int *pu, int *pv)
{
*pu=0;
*pv=0;
return;
}
Ans  :  1 3 0 0

Ques : What would be printed on the standard output as a result of the following code snippet?

main( )
{
char *str[ ] = {
"Manish"
"Kumar"
"Choudhary"
};
printf ( "\nstring1 = %s", str[0] );
printf ( "\nstring2 = %s", str[1] );
printf ( "\nstring3 = %s", str[2] );
}
Ans  : string1 = ManishKumarChoudhary string2 = (null) string3 = (null)

Ques : Which standard function is used to deallocate memory allocated by the malloc() function?
Ans  : free

Ques : The declaration int (*p[5])() means:
Ans  : p is an array of pointers to functions the return type of which is an integer

Ques :What will be printed on the standard output as a result of the following code snippet?

void main()
{
        int arr[5]={1,2,3,4,5};
        printf("%d\n", *(arr+4));
}
Ans  : 5

Ques : What does the argv[0] represent?
Ans  :  The program name

Ques : What will happen when the following code is executed?

void main()
{
    char arr1[] = "REGALINT";
    char arr2[10] = "REGALINT";
    printf("%d,",sizeof(arr1));
    printf("%d",sizeof(arr2));
}
Ans  :   9,10

Ques : What would be printed on the standard output as a result of the following  code snippet?

main()
{
        enum {red, green, blue = 0, white};
        printf("%d %d %d %d", red, green, blue, white);
        return 0;
}
Ans  : 0 1 0 1

Ques : What is wrong with the following function prototype statement?

int func();
Ans  : While calling a function, the type int is not needed

Ques : What will be printed on the standard output as a result of the following code snippet?

void main()
{
        char arr[] = {'R','A','M'};
        printf("%d",strlen(arr));
}
Ans  : Cannot be determined

Ques : Which of the following is not a storage type?
Ans  :  auto

Ques :If a two dimensional array arr[4][10](an array with 4 rows and 10 columns) is to be passed in a function, which of the following would be the valid parameters in the function definition?
Ans  :  fn(int arr[4][10])

Ques : Which of the following is not a string function?
Ans  : strcomp()

Ques : What would be printed on the standard output as a result of the following code snippet?

char i = 'A';
char *j;
j = & i;
*j = *j + 32;
printf("%c",i);
Ans  : a

Ques : What will be printed on the standard output as a result of the following code snippet?

void main()
{
        char arr1[] = "REGALINT";
        printf("%d,",strlen(arr1));
        printf("%d",sizeof(arr1));
}
Ans  : 8,9

Ques : What will be printed on the standard output as a result of the following code snippet?

int funr(int x, int y)
{
        if(x <= 0)
        {
                   return y;
        }
        else
        {
                return (1+funr(x-1,y));
        }
}

void main()
{
    printf("%d",funr(2,3));
}
Ans  : 5

Ques : What would be printed on the standard output as a result of the following code snippet?

#define Name Manish
main()
{
printf("My name""Name");
}
Ans  : My nameName

Ques : What will be printed on the standard output as a result of the following code snippet?

main()
{
        int num = 425;
        printf("%d", printf("%d", num));
}
Ans  : 4253

Ques : What would be printed on the standard output as a result of the following code snippet?

main()

{

        signed char i = 1;

        for (; i<=255; i++)

        printf ("%d ",i);

        return 0;

}
Ans  : 1 2 3 . . . 127 -128 -127 ... 0 1 2 3 . . . (infinite times)

Ques :   What would be printed on the standard output as a result of the following code snippet?

#define max(a, b) ((a) > (b)?(a):(b))
main()
{
        int a=4;
        float b=4.5;
        printf("%.2f\n",max(a, b));
}
Ans  : 4.50

Ques :  Which of the following is not a file related function?
Ans  : puts()

Ques : What would be printed on the standard output as a result of the following code snippet?

#define max(a, b)((a) > (b)?(a):(b))
main()
{
int a=4, c = 5;
printf("%d ", max(a++, c++));
printf("%d %d\n", a,c);
}
Ans  : 6 5 7

Ques : Which of the following file modes would mean read + append?
Ans  : a+

Ques : What would be printed on the standard output as a result of the following code snippet?

int Recur(int num)
{
if(num==1 || num==0)
return 1;
if(num%2==0)
return Recur(num/2)+2;
else
return Recur(num-1)+3;
}

int main()
{
        int a=9;
        printf("%d\n", Recur(a));
        return 0;
}
Ans  : 10

Ques : What will happen when the following code is executed?

{
int num;
num =0;
do {-- num;
printf("%d\n", num);
num++;
} while (num >=0);
}
Ans  : The loop will run infinitely

Ques : Which of the following functions is used to extract formatted input from a file?
Ans  :  fscanf()

Ques : What does the following function do?

int fn(unsigned int x)
{
        int count = 0;
        for(; x!=0; x&=(x-1))
                count++;
        return count;
}
Ans  : Returns the number of 1 bits(bits having one) in the number x

Thanks for watching this test Question & Answers. Please don't forget to leave a comment about this post. You can also find some more effective test question & answers, information, techniques, technology news, tutorials, online earning information, recent news, results, job news, job exam results, admission details & another related services on the following sites below. Happy Working!
News For Todays ARSBD oEtab ARSBD-JOBS DesignerTab

UpWork (oDesk) & Elance Objective-C Test Question & Answers

/ No Comments
UpWork (oDesk) & Elance Objective-C Test Question & Answers are really very important to pass UpWork & Elance test. You will get top score at this skill test exam. If you found any problem or wrong answer please inform me via contact or comments. We will try to solve it in short. This test is extremely valuable to acquire knowledge of Objective-C. Lets Start test.


Ques : Which of the following is the fastest?
Ans  : Mutex implicit locking

Ques : How do you free an object?
Ans  :  [obj release]

Ques :  What is the isa variable in objects?
Ans  : Object class identification

Ques : What is true regarding C functions inside .m files?
Ans  : They can contain Obj-C code

Ques : What does the following imply?

Worker *ceo = [[Worker alloc] init];
ceo->boss = nil;
Ans  : That the boss instance variable is declared @public

Ques : Can you send messages to nil?
Ans  : Yes

Ques :  In which version of Objective-C did the fast enumeration system appear?
Ans  : 2.0

Ques : What comments are supported in Obj-C?
Ans  :  // Line comments

Ques : What type of variable do you need to use to implement singletons?
Ans  : static

Ques : As categories can't have instance variables, what class could you use to implement a full class only with categories?
Ans  :  NSMutableDictionary

Ques : How do you throw an exception?
Ans  : @throw exception

Ques : What is true regarding strings?
Ans  : Obj-C strings are not of static storage

Ques : How do you include the root "Object" class?
Ans  : It depends on the compiler

Ques : What is true regarding @protected?
Ans  : The instance variable is accessible within the class that declares it and within classes that inherit it

Ques : What is a protocol?
Ans  :  An interface without an implementation

Ques :  Which of the following is incorrect?
Ans  : [AClass release]

Ques : How do you allocate an object?
Ans  : MyClass *obj = [MyClass alloc];

Ques : What will be the output of the following code?

static int
a (void)
{
printf ("a\n");
return 0;
}

static int
b (void)
{
printf ("b\n");
return 1;
}

static int
c (void)
{
printf ("c\n");
return 2;
}

int
main (int argc, const char *argv[])
{
printf ("%d %d %d", a (), b (), c ());
return 0;
}
Ans  : a b c 0 1 2

Ques : What is nil?
Ans  : The null object

Ques : Can an exception caught in @catch be re-thrown?
Ans  : Yes

Ques : What class specifiers are supported?
Ans  : There is no such thing as class specifiers

Ques : Which of the following declares a protocol?
Ans  : @protocol ProtocolName

Ques : What is the Obj-C runtime?
Ans  : A C library

Ques : What's the difference between copy and deepCopy?
Ans  : copy creates a copy at the first level, while deepCopy copies the instance variables

Ques : Which of the following can be inherited?
Ans  : Protocols

Ques : A method can be tagged to be called only by a specific class and its subclasses.
Ans  : False

Ques : Which of the following is not recommended?
Ans  : None of the above

Ques : A class can have two methods with the same name, but with different argument types.
Ans  : False

Ques : What are @try and @catch?
Ans  :  Exception keywords

Ques : A class can conform to only one protocol.
Ans  : False

Ques : Which of the following creates a class that conforms to a protocol?
Ans  : @interface ClassName

Ques : What is the id type?
Ans  :  A generic C type that Objective-C uses for an arbitrary object

Ques : What is a @finally block?
Ans  :  A block of code that is run whenever an exception is thrown or not

Ques : Is the following code a correct allocation?

MyClass myObj;
[&myObj aMessage];
Ans  : No

Ques : What is not supported in Obj-C?
Ans  : Method argument default value

Ques : Which of the following does not happen when you throw an exception in a @synchronized block?
Ans  : The object is deallocated

Ques : What can be linked to an Obj-C program without any particular process?
Ans  : C libraries

Ques : What is the C type used to work with objects in Obj-C?
Ans  : pointer

Ques : What is a category?
Ans  :  A category is a way to add methods to a class which already exists

Ques : Protocols are like classes; they can inherit.
Ans  : True

Ques : Which of the following is false?
Ans  : When a method is called, the send is automatically available as the sender variable, like self or super

Ques : What happens if two categories define methods with the same names for the same class?
Ans  :  At runtime, either method will be called

Ques : What can you do with categories?
Ans  : Add methods to a class without subclassing it

Ques : In which version of Objective-C did the properties system appear?
Ans  :  2.0

Ques : What is the default visibility for instance variables?
Ans  : @protected

Ques : What happens if you release an unretained object twice?
Ans  : MemoryException is raised

Ques : In Obj-C 2.0, what do the fast enumeration protocols rely on to provide fast Enumerations?
Ans  :  C arrays

Ques : What can you use to avoid the msgSend function overhead?
Ans  : SEL

Ques : Which C feature is not supported in Obj-C?
Ans  :  Support is compiler dependant

Ques : What does Obj-C not support?
Ans  : Automatic variables

Ques : When using the garbage collector, which method, that is normally called without the collector, is not called on your objects where they are collected?
Ans  : dealloc

Ques : What can be used as Object instance variables?
Ans  : pointers

Ques : What is a SEL?
Ans  : A pointer to a method

Ques : What is an IMP?
Ans  : The C type of a method implementation pointer

Ques : What is true regarding @public?
Ans  : It breaks encapsulation

Ques : What is an autoreleased object?
Ans  : An object that will be released when the current AutoreleasePool is deallocated.

Ques : If you need to allocate custom memory, in which method will you do so?
Ans  : None of the above

Ques : What is #import
Ans  :  C preprocessor construct to avoid multiple inclusions of the same file

Ques : What is true regarding messaging?
Ans  :  Messaging is fully dynamic, which means you can compile some code that sends a message to a class that doesn't implement it, and add a category later, in a dynamic library for example

Thanks for watching this test Question & Answers. Please don't forget to leave a comment about this post. You can also find some more effective test question & answers, information, techniques, technology news, tutorials, online earning information, recent news, results, job news, job exam results, admission details & another related services on the following sites below. Happy Working!
News For Todays ARSBD oEtab ARSBD-JOBS DesignerTab

UpWork (oDesk) & Elance C++ Programming Test Question & Answers

June 28, 2015 / No Comments
UpWork (oDesk) & Elance C++ Programming Test Question & Answers are really very important to pass UpWork & Elance test. You will get top score at this skill test exam. If you found any problem or wrong answer please inform me via contact or comments. We will try to solve it in short. This test is very valueable to acquire knowledge of this skill. Lets Start test.


Ques : Consider the following code:
    class A {
          typedef int I;      // private member
          I f();
          friend I g(I);
          static I x;
      };
Which of the following are valid:
Ans  :
 A::I A::f() { return 0; }
 A::I g(A::I p = A::x);
 A::I g(A::I p) { return 0; }

Ques : Consider the following class hierarchy:


class Base

{

}


class Derived : public Base

{

}


Which of the following are true?
Ans  :  Derived can access public and protected member functions of Base + The following line of code is valid: Base *object = new Derived();

Ques : What linkage specifier do you use in order to cause your C++ functions to have C linkage
Ans  :  extern "C"

Ques : Sample Code


typedef char *monthTable[3];


Referring to the code above, which of the following choices creates two monthTable arrays and initializes one of the two?
Ans  : monthTable winter,spring={"March","April","May"};

Ques :  What access specifier allows only the class or a derived class to access a data membe
Ans  : protected

Ques : What is the output of the following code segment?

int n = 9;

int *p;

p=&n;

n++;

cout << *p+2 << "," << n;
Ans  : 12,10

Ques : What does ADT stand for?
Ans  : Abstract data type

Ques :  Consider the sample code given below and answer the question that follows.
class Shape
{
public:
virtual void draw() = 0;
};

class Rectangle: public Shape
{
public:
void draw()
{
// Code to draw rectangle
}
//Some more member functions.....
};

class Circle : public Shape
{
public:
void draw()
{
// Code to draw circle
}
//Some more member functions.....
};

int main()
{
Shape objShape;
objShape.draw();
}
What happens if the above program is compiled and executed?
Ans  : A compile time error will be generated because you cannot declare Shape objects

Ques : Consider the sample code given below and answer the question that follows.


class Person

{

public:

   Person();

      virtual ~Person();

};

class Student : public Person

{

public:

   Student();

   ~Student();

};


main()

{

   Person *p = new Student();

   delete p;

}


Why is the keyword "virtual" added before the Person destructor?
Ans  : To ensure that the destructors are called in proper orde

Ques : If input and output operations have to be performed on a file, an object of the _______ class should be created.
Ans  :  fstream

Ques : In the given sample Code, is the constructor definition valid?


class someclass

{

   int var1, var2;

   public:

      someclass(int num1, int num2) : var1(num1), var2(num2)

      {

      }

};
Ans  : Yes, it is valid

Ques : Consider the sample code given below and answer the question that follows.


template Run(T process);


Which one of the following is an example of the sample code given above?
Ans  : A template function declaration

Ques : Which of the following sets of functions do not qualify as overloaded functions?
Ans  : void x(int,char) int *x(int,char)

Ques : Consider the sample code given below and answer the question that follows.


1  class Car

2  {

3  private:

4  int Wheels;

5

6  public:

7  Car(int wheels = 0)

8  : Wheels(wheels)

9  {

10 }

11

12 int GetWheels()

13 {

14 return Wheels;

15 }

16 };

17 main()

18 {

19 Car c(4);

20 cout << "No of wheels:" << c.GetWheels();

21 }


Which of the following lines from the sample code above are examples of data member definition?
Ans  :  4

Ques : Which of the following statements about function overloading, is true?
Ans  :  Function overloading is possible in both C and C++

Ques : You want the data member of a class to be accessed only by itself and by the class derived from it. Which access specifier will you give to the data member?
Ans  :  Protected

Ques : Consider the sample code given below and answer the question that follows.


class Person

{

    string name;

    int age;

    Person *spouse;

public:

    Person(string sName);

    Person(string sName, int nAge);

    Person(const Person& p);


    Copy(Person *p);

    Copy(const Person &p);

    SetSpouse(Person *s);

};


Which one of the following are declarations for a copy constructor?
Ans  :  Person(const Person &p);

Ques : Which of the following member functions can be used to add an element in an std::vector?
Ans  : push_back

Ques : Which of the following are NOT valid C++ casts
Ans  :  void_cast

Ques : Consider the sample code given below and answer the question that follows:


     char **foo;
    /* Missing code goes here */
    for(int i = 0; i < 200; i++)
    {
        foo[i] = new char[100];
    }

Referring to the sample code above, what is the missing line of code?
Ans  : font size=2>foo = new char*[200];

Ques : Consider the line of code given below and answer the question that follows.

class screen;

Which of the following statements are true about the class declaration above?
Ans  : The syntax is correct

Ques : Which of the following are true about class member functions and constructors?
Ans  : A member function can return values but a constructor cannot

Ques : Consider the following code:


#include


int main(int argc, char* argv[])
{
        enum Colors
        {
                red,
                blue,
                white = 5,
                yellow,
                green,
                pink
        };

        Colors color = green;
        printf("%d", color);
        return 0;
}

What will be the output when the above code is compiled and executed?
Ans  : 11

Ques : Which of the following statements regarding functions are false?
Ans  :  You can create arrays of functions

Ques : Consider the following code:


#include

using namespace std;


class A
{
public :

        A()

        {

                cout << "Constructor of A\n";

        };

        ~A()

        {

                cout << "Destructor of A\n";

        };

};


class B : public A

{
public :

        B()

        {

                cout << "Constructor of B\n";

        };

        ~B()

        {

                cout << "Destructor of B\n";

        };

};


int main()
{

        B        *pB;

        pB = new B();

        delete pB;

        return 0;

}


What will be the printed output?
Ans  : Constructor of A Constructor of B Destructor of B Destructor of A

Ques : Consider the following code:
template void Kill(T *& objPtr)
{
   delete objPtr;
   objPtr = NULL;
}

class MyClass
{
};

void Test()
{
   MyClass *ptr = new MyClass();
   Kill(ptr);
   Kill(ptr);
}
Invoking Test() will cause which of the following?
Ans  : Code will execute properly

Ques : Consider the following statements relating to static member functions and choose the appropriate options:

1. They have external linkage
2. They do not have 'this' pointers
3. They can be declared as virtual
4. They can have the same name as a non-static function that has the same argument types
Ans  : Only 1 and 2 are true

Ques : What will be the output of the following code?

class b

{
    int i;

    public:

    virtual void vfoo()

  {

    cout <<"Base ";

  }

};

class d1 : public b

{

    int j;

    public:

    void vfoo()

  {

    j++;

    cout <<"Derived";

  }

};

class d2 : public d1

{

    int k;

};

void main()

{

    b *p, ob;

    d2 ob2;

    p = &ob;

    p->vfoo();

    p = &ob2;

    p->vfoo();

}
Ans  :  Base Derived

Ques :  Consider the following code:


#include

using namespace std;


int main()
{

cout << "The value of __LINE__  is " <<__line__ span="">


return 0;

}


What will be the result when the above code is compiled and executed?
Ans  : The code will compile and run without errors

Ques : Which of the following STL classes is deprecated (i.e. should no longer be used)?
Ans  :  ostrstream

Thanks for watching this test Question & Answers. Please don't forget to leave a comment about this post. You can also find some more effective test question & answers, information, techtunes, technology news, tutorials, online earning information, recent news, results, job news, job exam results, admission details & another related services on the following sites below. Happy Working!
News For Todays ARSBD oEtab ARSBD-JOBS DesignerTab