CBSE - MCQ Question Banks (के. मा. शि. बो . -प्रश्नमाला )

PreviousNext

Q. 190501 The function that sets the current put position in a stream is


A. seekp().

B. tellp().

C. get().

D. put().

Right Answer is: A

SOLUTION

Every file maintains two pointers called get_pointer(in input mode file) and put_pointer(in output mode file) which tells the current position in the file where writing or reading will take place.


Q. 190502 A constant describing how a file is to be used is known as


A. stream.

B. object.

C. file mode.

D. binary.

Right Answer is: C

SOLUTION

The file mode describes how a file is to be used : to read from it, to write to it, to append it and so on.


Q. 190503 Functions available for file I/O error handling are


A. bad( ) and good( ).

B. seekp( ) and tellp( ).

C. get( ) and put( ).

D. get( ) and getline( ).

Right Answer is: A

SOLUTION

Whenever an I/O function that takes a file handle as an input parameter raises an error, it will pass this file handle as a third parameter to the error handler function.


Q. 190504 Members of ofstream class are


A. seekp() and tellp().

B. get() and put( ).

C. get() and getline().

D. bad() and good().

Right Answer is: A

SOLUTION

seekp() and tellp() are used to manipulate the put_pointer used for performing write operations on a file.


Q. 190505 A flow of bytes into or out of a program is known as


A. file.

B. stream.

C. buffer.

D. template.

Right Answer is: B

SOLUTION

A stream is an abstraction that represents a device on which input and output operations are performed. A stream can basically be represented as a source or destination of characters of indefinite length.


Q. 190506 The function that determines the end-of-file operation is


A. fail( ).

B. good( ).

C. eof( ).

D. bad( ).

Right Answer is: C

SOLUTION

In computing, end-of-file, commonly abbreviated EOF is a condition in a computer operating system where no more data can be read from a data source. The data source is usually called a file or a stream.


Q. 190507 The functions which manipulates get-pointer and put-pointer in the file are


A. get() and getline().

B. seekg() and seekp().

C. tellg() and tellp().

D. eof() and fail().

Right Answer is: B

SOLUTION

These functions operate on an offset calculation from the beginning, end, or current position in the stream.


Q. 190508 In C++, by default, files are treated as


A. text file.

B. binary file.

C. media file.

D. archive file.

Right Answer is: A

SOLUTION

A text file is a kind of computer file that is structured as a sequence of lines. A text file exists within a computer file system.


Q. 190509 The function that provides both input and output operations is


A. ifstream.

B. filebuf.

C. ofstream.

D. fstream.

Right Answer is: D

SOLUTION

File processing in C++ is performed using the fstream class. To perform file processing, you can declare an instance of an fstream object. If you do not yet know the name of the file you want to process, you can use the default constructor. Unlike the FILE structure, the fstream class provides two distinct classes for file processing. One is used to write to a file and the other is used to read from a file.


Q. 190510 The function which provides output operations is


A. ifstream.

B. filebuf.

C. ofstream.

D. fstream.

Right Answer is: C

SOLUTION

The ofstream function provides an interface to write data to files as output streams.


Q. 190511 The function which sets the file buffers to read and write is


A. ifstream.

B. filebuf.

C. ofstream.

D. fstream.

Right Answer is: B

SOLUTION

Class hierarchy: streambuf - - > filebuf. filebuf class applies the functionality of the streambuf class to read and write from/to files.


Q. 190512 If the file content before the execution of the program is string “ABC”, the output of the following program #include< iostream.h >
#include< fstream.h > void main()           {      char ch = ‘A’;                    fstream fileout(“data.dat”,ios::out);                    fileout  <<  ch ;                    int p = fileout.tellg();                    cout  <<  p;            }         


A. 0.

B. 1.

C. 2.

D. 3.

Right Answer is: B

SOLUTION

The tellg() gets the position of put pointer and therefore the output will be 1.


Q. 190513 A “student.dat” file exists, with the object of class students. Assume that the file has just been opened through the object file of fstream class. A single command to place the file pointer to the third record from beginning is


A. file.seek(3*sizeof(student), ios::beg);

B. fil.seekg(3*sizeof(student), ios::beg);

C. file.seek(2*sizeof(student), ios::beg);

D. file.seek(3*size(student), ios::beg);

Right Answer is: B

SOLUTION

The function seekg() sets current get position in a stream.


Q. 190514 Identify the error in the following code
                      void main(){     int A[]={2,4,6,8,10};     for(int i=0;i<3;++i)         cout<< *A++;                       }


A. size of array is not given

B. condition given is wrong

C. A cannot be incremented

D. no error

Right Answer is: C

SOLUTION

A is the array name and contains the starting address.


Q. 190515 The output of the following code is #include < iostream.h> void main(){    float p = 2.125 ;    float*a,*b;    a=&p;    b=a;    cout << p<< ' ' << *(&p) << ' '<< *a+*b;                     }


A. 2.125 2.125 4.25.

B. 2.125 2.125 2.125 2.125.

C. 2.125 2.125 4.5156.

D. cannot be predicted as address is unknown.

Right Answer is: A

SOLUTION

The reason for this is p gives the value stored in the variable p. *(&p) gives the data value stored in the address &p i.e., the data value of x. Since a points to p, *a gives the value of p. Also, b has the same address as that of a, *b also gives the value of a which in turn produces the addition of *a and *b i.e. 2.125 + 2.125.


Q. 190516 When the objects that are allocated memory dynamically, are not deleted and the memory block reamins occupied till the end of the program, such memory blocks are known as


A. stacks.

B. heaps.

C. orphaned memory blocks.

D. parental memory blocks.

Right Answer is: C

SOLUTION

These orphaned memory blocks when increase in number, bring an adverse effect on the system. This situation is known as memory leak.


Q. 190517 Address of an object is passed to a member function using


A. the class pointer.

B. the data members.

C. the this pointer.

D. an array of pointers.

Right Answer is: C

SOLUTION

When a member function is called, it is automatically passed an implicit argument that is a pointer to the object that invoked the function. This pointer is called 'this'.


Q. 190518 A function that returns reference


A. can appear on the left of the = sign.

B. can accept only references are arguments.

C. is always called by value.

D. can also return a pointer.

Right Answer is: A

SOLUTION

A function returning a reference can appear on the left-hand side of an assignment statement.
For example, min(x,y) = -2;


Q. 190519 An array of pointers


A. is an array of addresses.

B. does not have a base type.

C. cannot hold addresses of objects.

D. cannot be used with the for(;;) loop.

Right Answer is: A

SOLUTION

Pointers also, may be arrayed like any other data type. To declare an array holding 5 int pointers, the declaration would be as follows:
int *ip[5];     //array of 5 int pointers
After this declaration, contiguous memory would be allocated for 5 pointers that can point to integers.


Q. 190520 Memory leaks occur when


A. delete statement is not executed.

B. memory is allocated dynamically.

C. there is no memory to allocate.

D. there are too many variables.

Right Answer is: A

SOLUTION

Many possible reasons lead to the situation of memory leaks. Most common of these are:
1. forgetting to delete something that has been dynamically allocated (i.e., using new)
2. failing to notice that code may bypass a delete statement under certain circumstances.
3. assigning the result of a new statement to a pointer that was already pointing to an allocated object.


Q. 190521 The statement
        int *as = new int(10);


A. creates an array of 10 elements whose address is in as.

B. creates an integer array initialized to 10.

C. creates an integer pointer and assigns 10 to it.

D. assigns 10 to a location whose address is in as.

Right Answer is: D

SOLUTION

It allocates memory of one integer to as and intializes it with value 10.


Q. 190522 When an integer pointer is incremented, its value increases by


A. 1.

B. 4.

C. 2.

D. 3.

Right Answer is: C

SOLUTION

In pointer arithmetic, all pointers increase and decrease by the length of the data type they point to.


Q. 190523 The statement
int *ptr = new int [10];


A. allocates memory of one integer to ptr and initializes it with value 11.

B. allocates memory of one integer to ptr and initializes it with value 10.

C. allocates memory of 10 contiguous integers and stores beginning address in pointer ptr.

D. allocates memory of 11 contiguous integers and stores beginning address in pointer ptr.

Right Answer is: C

SOLUTION

The statement
int *ptr = new int[10];
allocates memory of 10 contiguous integers and stores beginning address in pointer ptr. Whereas, the statement
int *ptr = new int (10);
allocates memory of one integer to ptr and initializes it with value 10.


Q. 190524 An integer pointer can be declared by


A. int & ans;

B. int *ans;

C. int ans*;

D. *int ans;

Right Answer is: B

SOLUTION

Pointer variables are declared like normal variables except for the addition of the unary * character. The general form of a particular declaration is as follows :
type * var_name;


Q. 190525 Using structure pointers, the members of structures are accessed using


A. . operator.

B. -> operator.

C. -< operator.

D. <- operator.

Right Answer is: B

SOLUTION

To refer to the structure members using -> operator, it is written as
struct pointer -> structure-member.


Q. 190526 A reference is


A. a variable that stores address of another variable.

B. a variable that stores value  of another variable.

C. also regarded as the name of an array.

D. another name for a variable.

Right Answer is: D

SOLUTION

A reference is a type of pointer and when it is declared it must be initialised with the variable it is a reference to.


Q. 190527 A pointer is


A. a variable that can store memory address.

B. an arrow towards a variable.

C. declared using  ‘&’.

D. a variable that does not have an address.

Right Answer is: A

SOLUTION

A pointer is a variable that holds a memory address, usually the location of another variable in memory.


Q. 190528 Static memory allocation is


A. done using the free store of computer’s memory.

B. done through special operator, new.

C. done when memory requirements are known beforehand.

D. used to declare arrays in memory.

Right Answer is: C

SOLUTION

When the amount of memory to be allocated is known beforehand and the memory is allocated during compilation itself, it is referred to as static memory allocation.


Q. 190529 Dynamic allocation of memory is


A. done when program is compiled.

B. done at run time.

C. done using the stack.

D. used to pass arguments.

Right Answer is: B

SOLUTION

When the amount of memory to be allocated is not known beforehand rather it is required to allocate (main) memory as and when required during runtime itself, then, the allocation of memory at run time is referred to as dynamic memory allocation.


Q. 190530 The name of an array is a pointer pointing to the


A. first element of the array.

B. last element of the array.

C. middle element of the array.

D. second last element of the array.

Right Answer is: A

SOLUTION

An array is a group of homologous elements in memory, whereas a pointer is a variable that holds a memory address.


Q. 190531 A value that any pointer may take to represent that it is pointing to "nowhere" is known as


A. null pointer.

B. zero pointer.

C. empty pointer.

D. constant pointer.

Right Answer is: A

SOLUTION

A null pointer is a regular pointer of any pointer type which has a special value that indicates that it is not pointing to any valid reference or memory address.


Q. 190532 The pointer pointing to a constant variable is


A. pointer to a constant.

B. constant pointer.

C. fixed pointer.

D. function pointer.

Right Answer is: A

SOLUTION

Using a pointer to a constant, the constant value can not be modified, however the pointer can be made to point to another location.


Q. 190533 The two operators for dynamic memory allocation and deallocation are known as


A. plus and minus.

B. static and dynamic.

C. new and old.

D. new and delete.

Right Answer is: D

SOLUTION

The two operators that C++ offers for dynamic memory allocation and deallocation are new and delete. The operator new allocates the memory dynamically and returns a pointer storing the memory address of the allocated memory. The operator delete deallocates the memory pointed by the given pointer.


Q. 190534 What is the ‘this’ pointer?
A. plus and minus.
B. static and dynamic.
C. new and old.
D. new and delete.

Right Answer is:

SOLUTION

The member functions of a class exist at one place in memory and are used by all the objects.  When an object calls a function, the function is automatically passed a pointer to that object.  Thus, the function has the address of the object and can use its data.  This pointer is called the ‘this’ pointer.
E
xample –

#include< iostream.h>

class stu{

   int rno;

   int marks;

  public:

   stu(int a, int b){

      rno=a;

      marks=b;

   }

   void disp(stu s){

     cout<< this->rno;

     cout<< this->marks;

     cout<< "nPassed Object";

     cout<< s.rno;

     cout<< s.marks;

   }

};

void main(){

  stu s1(10,100);

  stu s2(11,98);

  s2.disp(s1);

}

 

The output of this program clearly shows that s2 is the object associated with ‘this’ when s2 calls the member function.  As ‘this’ is a pointer, it uses the arrow operator ‘->’ and not the dot ‘.’ operator to access members.


Q. 190535 Show how pointers to structure can be passed to a function.
A. plus and minus.
B. static and dynamic.
C. new and old.
D. new and delete.

Right Answer is:

SOLUTION

#include< iostream.h>
      
struct item{
            
         int code;

    int price;

   };

item* func(item *ptr){

  cin>>ptr->code;

  cin>>ptr->price;

  return ptr;

}

void main(){

   item i1,*pi;

   pi = func(&i1);          // function call

   cout<< "from Pointer "<< pi->code<< pi->price;

   cout<< "from variable "<< i1.code<< i1.price;

}                          

 

Here, i1 is a structure variable and pi is a pointer.  Address of i1 is passed to the function that accepts values and returns a pointer.


Q. 190536 Give an example to show a function returning  a pointer to an object.
A. plus and minus.
B. static and dynamic.
C. new and old.
D. new and delete.

Right Answer is:

SOLUTION

          #include< iostream.h>

class Emp{

       int code;

   public :

       void getdat(int x){code=x;}

       void dispdat(){cout<< "code = "<< code;}

};

Emp* func(int x, Emp &Em){

  Emp *p;

  Em.getdat(x);

  cout<< "Value passed";

  p = &Em;

  return p;

}

void main(){

   Emp e1, e2;

   Emp *ep;

   e2.getdat(3);

   ep = func(5,e1);  // function call

   e1.dispdat();

   e2.dispdat();

   ep->dispdat();

}         

 

Pointer p is assigned the address of the object in the function func(), and returned.  When the function dispdat() is called with the pointer, the arrow operator is used.


Q. 190537 What is a dynamic structure?
A. plus and minus.
B. static and dynamic.
C. new and old.
D. new and delete.

Right Answer is:

SOLUTION

Once a structure has been defined, variables, including pointers can be declared for it.  When memory is allocated dynamically for a structure, it is called a dynamic structure.
Example

struct A{

     int a;

     char b;

};

A v1,*v2;

v2=new A;

Remember, variables created using new must be deleted when no longer needed, by delete.


Q. 190538 What are self referential structure?
A. plus and minus.
B. static and dynamic.
C. new and old.
D. new and delete.

Right Answer is:

SOLUTION

A structure that has a member that refers to the structure itself is known as a self referential structure.
Example -

struct guest{

     int tel;

     char name[20];

     guest *next;            // pointer to type guest

};

 

Here, structure guest is a self referential structure. It has a member, next, which stores the address of guest type.


Q. 190539 How is passing references to a function different from passing pointers?
A. plus and minus.
B. static and dynamic.
C. new and old.
D. new and delete.

Right Answer is:

SOLUTION

In both the cases, the original data changes after the function call.       
When reference is passed, the prototype is something like –

void func1(int &, int &);          

The actual parameters are simply given new names and accessed through them. The function call is the same as the call when function is called by value.

 

When pointers are passed, the prototype is something like -

void func2(int *, int *);          

When the function is called, addresses are passed. These addresses are stored in pointer variables by the function and the data at these addresses is accessed.


Q. 190540 What is the difference between  constant pointers and pointers to constants?
A. plus and minus.
B. static and dynamic.
C. new and old.
D. new and delete.

Right Answer is:

SOLUTION

A constant pointer means that the address in it cannot be changed. 

int a=12;                 // integer variable with value 12

int  *pa = &a;           // pointer pa stores address of a

++pa;                      // increment (address in)  pa

 

int *const cpa=&a;    // constant pointer named cpa stores address of a

++cpa;                    //error, constant pointer cannot be changed

 

A pointer to a constant means that the pointer holds the address of a constant. 

const int cnum=23;                // constant cnum declared

const int *pcnum = &cnum;    // pointer to a constant stores address of cnum

++cnum;                             // Error,  cnum is a constant    

         ++pcnum;                            // increment address in pcnum


Q. 190541 Describe an array of pointers.
A. plus and minus.
B. static and dynamic.
C. new and old.
D. new and delete.

Right Answer is:

SOLUTION

An array of pointers is an array, each element of which is a pointer.
An array of integer pointers would be declared as – int *N[5]; 

Now, each of the array elements, N[0], N[1], N[2], N[3] and N[4] would hold the address of an integer variable. Look at the statements below –

 

          int a = 12;

          int b = 23;

          int c = 34;

          int d = 45;

          int e = 56;

 

          N[0] = &a;

          N[1] = &b;

          N[2] = &c;

          N[3] = &d;

          N[4] = &e;

 

The following two statements would give the same output.

cout<< a;

cout<< *N[0];

 

Lets look at another example using a string.

 

char N[]=“Discover Wildlife”;

cout<< N;

cout<< *N;

cout<< *(N+1);

                             Output of these lines: Discover WildlifeDi

(code contd.)

char *p=N;

cout<< p;

cout<< *p;

cout<< *(p+1);

Output of these lines: Discover WildlifeDi

 

Again, the array name behaves exactly like the pointer.


Q. 190542 How are arrays and pointers related?
A. plus and minus.
B. static and dynamic.
C. new and old.
D. new and delete.

Right Answer is:

SOLUTION

The name of an array is regarded as a pointer.  It holds the address of the first element of the array.  Consider the statements below - 

int A[10] = {1,2,3,4,5,6,7,8,9,10};  

         

A is the array name, it holds the address of the first element A[0].

cout<< A;                 //displays the address of the first element

cout<< *A;               //displays value at that address i.e.  1

 

cout<< A+1;             //displays another address

cout<< *(A+1);          //displays  value at that address  i.e.  2

 

As you can see, A behaves just like a pointer.


Q. 190543 How are ‘*’ and ‘&’ used with pointers?
A. plus and minus.
B. static and dynamic.
C. new and old.
D. new and delete.

Right Answer is:

SOLUTION

The ‘*’ is also called the indirection operator and ‘&’ is also called address of operator.
When a pointer is declared, the ‘*’ is used :-    int *pa;

When an address is to be stored the ‘&’ is used :-  pa = &a;

When the value at the address in the pointer is to be accessed (i.e. dereferenced), the ‘*’ is used, as in,    cout<<*pa;


Q. 190544 Why is the operator ‘delete’ used?
A. plus and minus.
B. static and dynamic.
C. new and old.
D. new and delete.

Right Answer is:

SOLUTION

The ‘delete’ operator frees (de-allocates) the memory pointed to by the pointer.
The memory allocated using new remains allocated until it is freed using the delete operator.  If the allocated memory is not de-allocated, then with every run of the program the amount of available memory decreases.  The general form of using the  delete operator is,

          delete pointer_variable_name;

 

delete pa;            // frees memory pointed to by pa

delete [10] A;      // frees memory allocated to array A, array size is optional

         delete [ ] X;         // frees memory allocated for array X


Q. 190545 How is the operator ‘new’ used?  Explain with the help of an example.
A. plus and minus.
B. static and dynamic.
C. new and old.
D. new and delete.

Right Answer is:

SOLUTION

The ‘new’ operator allocates memory dynamically and returns a pointer that stores the address of the location where memory has been allocated.  The general form of allocating is :
             pointer_variable_name = new  data_type;

 

Here, data type can be any valid data type, including structures and classes.  Bytes are allocated according to the data type and the address is stored in the pointer variable of the same data type. 

For example :       int *pa;

                               pa = new int;

                              *pa=12;                 // 12 is stored at the address in pa

Here, 2 bytes will be allocated for an integer which will be accessed through the address in pointer pa.

 


Q. 190546 How is  static memory allocation different from dynamic memory?
A. plus and minus.
B. static and dynamic.
C. new and old.
D. new and delete.

Right Answer is:

SOLUTION

Static Memory Allocation : when memory to be allocated is known beforehand, it is allocated during compilation.  Generally in a program, variables are declared along with data type and arrays are declared with size and memory is allocated accordingly.
Dynamic Memory Allocation : when the amount of memory required is not known beforehand, it is allocated while the program is running, and is known as dynamic memory allocation.  Two operators are used  - new and delete. Memory for allocation at runtime is obtained from the free store or heap.


Q. 190547 How is the memory organized when a program is executed?
A. plus and minus.
B. static and dynamic.
C. new and old.
D. new and delete.

Right Answer is:

SOLUTION

Four logically separate areas are created after a C++ program is compiled.
-  One area holds all the program statements that are to be executed i.e. the compiled program code.  

- The next area holds all the global variables being used. 

- The third area, also called Stack, stores all local variables, arguments passed to functions and the return address when functions are called. 

- The fourth area, called Heap or Free Store, is free memory which is dynamically allocated during program execution.


Q. 190548 Explain, using an example, how objects can be passed to a function as reference and how a function can return reference to an object.
A. plus and minus.
B. static and dynamic.
C. new and old.
D. new and delete.

Right Answer is:

SOLUTION

           #include< iostream.h>

class Emp{

       int code;

   public :

       void getdat(int x){code=x;}

       void dispdat(){cout<< "code = "<< code;}

};

Emp& func(int x, Emp& Em){

  Em.getdat(x);

  cout<< "Value passed";

  return Em;

}

void main(){

   Emp e1, e2;

   e2.getdat(3);

   func(5,e1) = e2;   //function call

   e1.dispdat();

   e2.dispdat();

                          

 

 

In this program an integer and an object as reference, are passed to function func().  Reference to the object is returned by the function.  The function call places the function on the left side of the = sign.  The returned variable is assigned the object e2.  When the objects are displayed, e1 and e2 both have the same output.


Q. 190549 What is memory leak?  What causes it?  How can it be avoided?
A. plus and minus.
B. static and dynamic.
C. new and old.
D. new and delete.

Right Answer is:

SOLUTION

When memory is allocated dynamically using the ‘new’ operator, it remains occupied even when the program is over.  Such occupied memory blocks are known as orphaned memory blocks .  Gradually, as the number of such blocks increases, there is less memory available to the program which affects its working.  This situation is called Memory Leak.
Some reasons for memory leak are - 

·          there is no delete in the program to free dynamically allocated memory  

·          the statement with delete is bypassed in certain situations

·          ‘new’ assigns the value to a pointer which already holds an address

Memory leak can be avoided by –

·          always freeing the dynamically allocated memory

                 ·           assigning the address passed by ’new’  to a fresh pointer.


Q. 190550 Write a program to store 5 names in an array of pointers, named list, and then reverse the order of these names in the array.
A. plus and minus.
B. static and dynamic.
C. new and old.
D. new and delete.

Right Answer is:

SOLUTION

       #include< iostream.h>
             
void main()

{

   char *tmp; int i,j;

   char *list[]={"Asia", "Bahamas","Canada","Denmark","England"};

   for( i=0;i< 5;i++)

       cout<< list[i]<< endl;

   for( i=0,j=4; i < 2;i++,j--)

{

       tmp=list[i];

       list[i]=list[j];

       list[j]=tmp;

}

   for( i=0;i < 5;i++)

      cout<< list[i]<< endl;

}


Q. 190551 Write a function that accepts a string as argument, removes all blanks from it and returns it.
A. plus and minus.
B. static and dynamic.
C. new and old.
D. new and delete.

Right Answer is:

SOLUTION

       #include< iostream.h>

void main()
{

    char A[80];

    char *str;

    char* funblank(char*);          // function prototype

    cout<< "Enter string ";

    cin.getline(A,80);

    str=funblank(A);                   // function call

    cout<< A<< endl;

    cout<< str<< endl;

}

   char* funblank(char* t)
{

   char *tmp;int i=0;

   while(*t !='?')
   {

       if(*t!=' ')
      {

          tmp[i]=*t;

          ++i;

       }

       ++t;

    }

    tmp[i]='?';

    return tmp;

         }


Q. 190552 A linear data structure among the following is


A. tree.

B. graph.

C. stack.

D. binary search tree.

Right Answer is: C

SOLUTION

In stack, the items are stored sequentially, thus forming a linear data structure.


Q. 190553 A non-linear data structure among the following is


A. array.

B. linked list.

C. stack.

D. tree.

Right Answer is: D

SOLUTION

In tree, the elements are not stored in a sequence therefore it’s a non-linear data structure.


Q. 190554 The sorting in which each successive element is picked and inserted at an appropriate position in the previously sorted array is


A. selection sort.

B. bubble sort.

C. insertion sort.

D. quick sort.

Right Answer is: C

SOLUTION

In insertion sort a single element is get considered at a time, inserting each in its suitable place.


Q. 190555 The sorting in which the adjoining values are compared and exchanged if they are not in proper order is


A. selection sort.

B. bubble sort.

C. insertion sort.

D. quick sort.

Right Answer is: B

SOLUTION

Bubble sort works by repeatedly stepping through the list to be sorted, comparing two items at a time and swapping them if they are in the wrong order.


Q. 190556 In C++, the constant from Limits.h, which can be used to store minimum possible integer value, is known as


A. INT_MAX.

B. INT_MIN.

C. INT_LIM.

D. INT_VAL.

Right Answer is: B

SOLUTION

Insertion sort works if the very first element stores the minimum element of the array. In C++, INT_MIN constant from Limits.h, can be used to store minimum possible integer value.


Q. 190557 The number of elements in an array A[-2..4, -3,..6] is


A. 8.

 

B. 10.

C. 70.

D. 18.

 

Right Answer is: C

SOLUTION

No. of rows = 4 - (-2) + 1 = 4 + 2 + 1 = 7
No. of columns = 6 - (-3) + 1 = 6 + 3 + 1 = 10
No. of elements = Rows X Columns = 7 X 10 = 70 elements.


Q. 190558 A special pointer, which stores the address of the object that is currently invoking a member function is


A. object pointer.

B. current pointer.

C. function pointer.

D. this pointer.

Right Answer is: D

SOLUTION

this pointer refers to the current object we are working on.


Q. 190559 The method, in which the value of each argument in the calling function is copied on to the corresponding formal arguments of the called-function is called


A. call by value.

B. call by reference.

C. call by address.

D. call by name.

Right Answer is: A

SOLUTION

In call by value method, the called function creates its own copies of original values sent to it. Any changes, that are made, occur on the function’s copy of values and are not reflected back to the calling function.


Q. 190560 Error in the code below is main() { int i, j; int *ip; i=j=ip=0; }


A. pointer cannot be used in assignment statement.

B. ip is a pointer and cannot be used as integer.

C. pointer should not be initialized.

D. pointer cannot be equal to zero.

Right Answer is: B

SOLUTION

A pointer points to the address of a variable. It cannot be used as integers.


Q. 190561 The correct output of the following program is # include < iostream.h> void main() { int i=5; int &j=i; int p=10; j=p; cout << endl << i<< endl<< j; p=20; cout << endl << i<< endl << j; }


A. 10 10 10 10.

B. 10 5 20 20.

C. 5 10 10 10.

D. 10 10 20 20.

Right Answer is: A

SOLUTION

j is a reference to i. If, we assign value of p to j, then value of i also changes.


Q. 190562 A named group of data which share similar properties or characteristics and have common behaviour among them is called


A. data item.

B. data type.

C. raw data.

D. information.

Right Answer is: B

SOLUTION

Data can be of different types. It can be numeric, alphabetic, or alphanumeric.


Q. 190563 The errors in the given code below is #include < iostream.h > const int i =10; void main() { const int i =20; cout << &i  <<  &::i ; }


A. compiler error : illegal structure declaration.

B. no error.

C. :: cannot be used with constant.

D. run-time error.

Right Answer is: A

SOLUTION

&::i is an illegal declaration used in the code.


Q. 190564 The errors in the code below is
# include < iostream.h > void main() { char c[]=”c++ is easy”; int i = strlen (c) ; cout <<  i ; }


A. no error.

B. c cannot be passed as an argument. It should be c[].

C. string.h header file is not defined.

D. no return statement for main ().

Right Answer is: C

SOLUTION

“string.h” header file defines the string functions like strlen, strcpy. These functions cannot be used without using string.h header file.  


Q. 190565 An example of simple data structure is


A. stack.

B. queue.

C. linked list.

D. array.

Right Answer is: D

SOLUTION

Simple data structures are normally built from primitive data types like integers, real, characters, boolean.


Q. 190566 A way of modelling real-life data in a specific context is known as


A. application level of data structure.

B. abstract level of data structure.

C. the implementation level of data structure.

D. the only way of designing data structure.

Right Answer is: A

SOLUTION

Application (or user) level is a way of modelling real-life data in a specific context, also called the problem domain. The data structure can be designed from user level perspective.


Q. 190567 The example(s) of non–primitive data types is/are


A. int.

B. float.

C. double.

D. union, structures.

Right Answer is: D

SOLUTION

Non-primitive data types are those data types types which are composed of primitive data types such as int, float, char.


Q. 190568 The code " int marks [30] " is a


A. structure.

B. single dimensional array.

C. multi dimensional array.

D. two dimensional array.

Right Answer is: B

SOLUTION

The syntax of single dimension array is “datatype arrayname[size]” whereas multi dimension arrays are accessed using more than one index. Example names[][]. It can be 2 dimensional or 3 dimensional.


Q. 190569 The value which can be assigned to char names[6] is


A. aditi.

B. priyanka.

C. amrita.

D. mudita.

Right Answer is: A

SOLUTION

One space is needed for null character, which acts as a terminator symbol.


Q. 190570 The value which can be assigned to char names[6] is


A. aditi.

B. priyanka.

C. amrita.

D. mudita.

Right Answer is: A

SOLUTION

One space is needed for null character, which acts as a termination symbol.


Q. 190571 The code: int marks [30], used in one of the C++ program, is


A. a structure.

B. single dimensional array.

C. multi dimensional array.

D. two dimensional array.

Right Answer is: B

SOLUTION

The syntax of single dimension array is “datatype arrayname[size]” whereas multi dimension arrays are accessed using more than one index. Example names[][]. It can be 2 dimensional or 3 dimensional.


Q. 190572 Example(s) of compound data structures is/are


A. arrays.

B. structures.

C. stacks and queues.

D. arrays and structures.

Right Answer is: C

SOLUTION

Simple data structures can be combined in various ways to form more complex structures called compound data structures.


Q. 190573 The total number of elements in the array int x[5] [6] is


A. 5 elements.

B. 29 elements.

C. 30 elements.

D. 11 elements.

Right Answer is: C

SOLUTION

The total number of elements in an array [a][b] is a x b. Here 5 x 6 =30.


Q. 190574 A pointer is a


A. constant

B. function

C. variable

D. data type

Right Answer is: C

SOLUTION

A pointer is a variable that holds a memory address, usually the location of another variable in memory.


Q. 190575 Dynamic allocation of memory is


A. done when program is compiled.

B. done at run time.

C. done using the stack.

D. used to pass arguments.

Right Answer is: B

SOLUTION

In computer science, dynamic memory allocation (also known as heap-based memory allocation) is the allocation of memory storage for use in a computer program during the runtime of that program.


Q. 190576 Static memory allocation is


A. done using the free store of computer's memory.

B. done through special operator, new.

C. done when memory requirements are known beforehand.

D. used to declare arrays in memory.

Right Answer is: C

SOLUTION

Static memory allocation refers to the process of allocating memory at compile-time before the associated program is executed, unlike dynamic memory allocation or automatic memory allocation where memory is allocated as required at run-time.


Q. 190577 Memory leaks occur when


A. memory is not released using delete operator.

B. memory is allocated dynamically.

C. there is no memory to allocate.

D. there are too many variables.

Right Answer is: A

SOLUTION

A memory leak or leakage in computer science is a particular type of memory consumption by a computer program where the program is unable to release memory it has acquired.


Q. 190578 An integer pointer can be declared by


A. int & ans;

B. int *ans;

C. int ans*;

D. *int ans;

Right Answer is: B

SOLUTION

The pointer is an integer that is intended to hold a memory address. The pointer may be an array or scalar. A pointer can be an assumed size array – that is, the last dimension may be left unspecified by using a '*' in place of a value – but a pointer cannot be an assumed shape array. No space is allocated for the pointer.


Q. 190579 Address of an object is passed to a member function using


A. class pointer.

B. data members.

C. this pointer.

D. an array of pointers.

Right Answer is: C

SOLUTION

The 'this' pointer is a pointer accessible only within the non-static member functions of a class, struct, or union type. It points to the object for which the member function is called.


Q. 190580 A function that returns reference


A. can appear on the left of the = sign.

B. can accept only references are arguments.

C. is always called by value.

D. can also return a pointer.

Right Answer is: A

SOLUTION

Functions can be declared to return a reference type. There are two reasons to make such a declaration. The information being returned is a large enough object that returning a reference is more efficient than returning a copy. The type of the function must be an l-value.


Q. 190581 An array of pointers


A. is an array of addresses.

B. does not have a base type.

C. cannot hold addresses of objects.

D. cannot be used with the for(;;) loop.

Right Answer is: A

SOLUTION

An array of pointers is used to store addresses of more than one data elements. Each element of the pointer array points to the address of an element.


Q. 190582 The statement int *marks will


A. define a pointer variable named marks.

B. access the address in marks.

C. access the value stored in marks.

D. store NULL value in the variable marks.

Right Answer is: A

SOLUTION

The pointer variable is used to store address of a varible. we can declare a pointer variable using astrick (*) Example: int *marks; Here marks is a pointer variable which can hold address of an integer variable.  


Q. 190583 Give the prototype of a function named funstring that returns a string and takes a string as argument, using pointers.
Right Answer is:

SOLUTION

char * funstring(char *);


Q. 190584 Write statements to display the address of a float type variable named rate.
Right Answer is:

SOLUTION

    float rate;
          float *fp;

          fp = &rate;

          cout<< fp;


Q. 190585 How is addition carried out with pointers?
Right Answer is:

SOLUTION

Every pointer has a base data type.  It holds the address of variables of that data type.  When 1 is added to a pointer, the size of the data type is added to it.  Suppose pointer pa holds the address of integer variable a, as 1001.  Adding 1 to pa will give 1003.  This is because the size of int is 2.
Suppose pf is a pointer that holds the address of float variable f, as 2300.  Adding 3 to pf will add  3 times the size of float i.e. 12, to the address in pf, making it 2312.


Q. 190586 Name the various regions in a C++ program's memory map.
Right Answer is:

SOLUTION

The four regions are:
1. Program code
2. Global variables
3. Stack
4. Heap


Q. 190587 What is Free Store ?
Right Answer is:

SOLUTION

Free Store is also called Heap. It is unallocated memory that is used during program execution. Memory that is dynamically allocated from this free store is unnamed and is manipulated through the address i.e. pointers.


Q. 190588 How are pointers different from reference variables?
Right Answer is:

SOLUTION

A reference variable is an alias or another name for an existing variable while a pointer is a variable that stores an address.  The reference does not occupy memory space but a pointer does. The declaration too is different –
         
int a;                      // variable  named a

int &alsoa = a;         // reference alsoa created, is an alias for a;

int  *pa;                // pointer pa created

pa=&a;                 // address of a stored in pa          

The value at the address in the pointer is accessed using the ‘*’ operator, called dereferencing.  In case of references, there is no such need, they directly give the value.


Q. 190589 What are pointers?
Right Answer is:

SOLUTION

Pointers are variables that store memory addresses.


Q. 190590 What is pointer to void?
Right Answer is:

SOLUTION

Normally when we declare a pointer, we give it a type which is the same as the type of the variable whose address it will store.  i.e.  int *ptr; will create pointer ptr which will hold addresses of integer variables.
Pointer to void is like a general purpose pointer that can store address of any data type.  It is used only in certain situations.To declare a pointer to void, give the statement  -  void * ptr;


Q. 190591 When A is an array ,  the expression A++ is invalid. Why?
Right Answer is:

SOLUTION

A is the address where the system has placed the array and it will stay here till the end of the program. As it is the base address of the array, it is a constant and cannot be changed. However, we can declare a pointer and assign A to it. Now, the pointer variable can be incremented, if required. 

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

int *p;

p=A;

            ++p;


Q. 190592 What is the difference between A[3] and *(A + 3)?
Right Answer is:

SOLUTION

A[3] refers to the value in array A with index number 3.
*(A + 3) refers to the value at the address A + 3.
In both the cases here, the same element is accessed.


Q. 190593 What is the difference between -
int *p1 = new int(12);              and int *p2 = new int [12];
Right Answer is:

SOLUTION

In statement -          int *p1 = new int(12);
Bytes are allocated in memory, to store an integer and initialized to 12, the address of this memory location is stored in pointer p1. 

 

In statement -          int *p2 = new int [12];

Bytes are allocated in memory for a 12 element integer array. The address of this memory location is stored in pointer p2. Now, p2 can be used just like the array name.


Q. 190594 An example of a non-linear data structure is


A. stack.

B. queue.

C. linked list.

D. tree.

Right Answer is: D

SOLUTION

Compound data structures are classified into following two types : Linear data structures and non-linear data structures. Linear data structures are single level data structures whereas non-linear data structures are multilevel data structures.


Q. 190595 A named collection of variables of different data types is known as


A. stack.

B. array.

C. data Structure.

D. queue.

Right Answer is: C

SOLUTION

Data Structure refers to a named collection of variables of different data types which can be possessed as a single unit.


Q. 190596 A specific representation of the structure and its accessing operations in a programming language is


A. application (or user) level of data structure.

B. logical level of data structure.

C. implementation level of data structure.

D. the only way of designing data structure.

Right Answer is: C

SOLUTION

There are different perspectives while designing a data structure. The implementation requires writing a set of procedures that create and manipulate instances of that structure.


Q. 190597 The examples of primitive data types are


A. arrays.

B. structures.

C. int, float, double.

D. class.

Right Answer is: C

SOLUTION

Primitive data types are fundamental or standard data types, such as integer, real or character data types.


Q. 190598 User defined data type is the another name for


A. primitive data type.

B. non-primitive data type.

C. fundamental data type.

D. standard data type.

Right Answer is: B

SOLUTION

Non-primitive data types are defined by the users. That is why, they are called as user defined data types.


Q. 190599 A character array is also known as


A. character string.

B. array.

C. integer.

D. character.

Right Answer is: A

SOLUTION

A string of characters is collection of character array. A character array is also known as character string.


Q. 190600 The code int marks [20] has


A. 0 to 20 subscripts.

B. 0 to 19 subscripts.

C. 1 to 20 subscripts.

D. 1 to 19 subscripts.

Right Answer is: B

SOLUTION

This is because the last element of an array is a null character ‘0’.


PreviousNext