Pageviews

Tuesday, 28 July 2020

+2].1.Structures and pointers - Solved Questions from textbook


                          PLUS TWO  COMPUTER SCIENCE

                                            Chapter 1. Structures and Pointers

                           (+2. Computer Science Questions and answers from text book) 


1. what is a structure?

        It is a user defined data type which represents logically related data items.It can represent a  group of different  types of data  under a common name

       Syntax: define the structure is

        struct structure_tag
  
         {
   
            data_type var1;
             data_type var2;
           ......................;
            data_type var N;
         };

2. Structure combines different type of data under a single unit.State whether this statement is true  or false?

 Ans. True

3. Which of the following is true for accessing an element of a structure.

  a) struct.element

    b) structure_tag.element

     c) struct_variable.element

      d) structure_tag.structure_variable

   Ans. c

4. What is a nested structure?Give a example.

        A Structure placed inside another structure is called a nested structure.

5.  A script is  for array ----------is associated with structure.

   Ans. Base address of the array

6. What is a pointer?

          The data stored in computer occupies a memory cell.Each cell has a unique address.A pointer points to the address of memory location.It holds the address of the memory location.

The syntax is 
 Data_Type *Pointer_Variable;

7. What is the criterion for  determining the datatype of a pointer?

           Pointer is a derived data type and hence a variable of pointer type is to be declared  prior to its use in the program.

8. If mks is a int variable  write the c++ statement to store its address in a pointer.

    int mks;
  int *ptr1;
ptr1=&mks;

9. If  ptr is an integer pointer  write c++ statement to allocate memory of an integer number an initialize  it with  12.
10. Consider the statements

        int *p;
       a=5;
       p=&a;
      cout<<*p+a;
      what is the value of output

   Ans.  10.

11. Dynamic memory allocation operator in c++ ------------

         Ans. new and delete

12.  What happens when the statement is executed
        int *p= new int(5)

13.  What is orphaned memory block?

           If the memory allocated using no operator is not free using delete,that memory is said to be orphaned memory block a block of memory that is left unused but not released for further allocation.

 14.  If p is an integer pointer which of the following is invalid
       
       a) cout<<*p;
        b) p=p*5;
         c) p>0;
          d)p++;
           e)p=1500;
            f)cout<<*p*2;

   Ans. Invalid: c,e

15. What is dynamic Array?
 
            It is an array created during at run time using new operator is called dynamic array.

16. Address of the  first location of an  array is known as -----------------

       Ans, Base address 

17. If arr is an integer array. Which of the following is invalid
    a) arr++;
     b) cout<< arr;
      c) cout<<*(arr+1);
       d) cin>>arr;
        e) arr=1500;
         f) cout<<*arr*2;

Ans. 
18. Write a declaration statement in C++ to refer to the names of 10 books using pointers.

  struct  Book;
{
  int book_id;
char book_name[10];
float book_price;
char author_name[10];
}
19.  Write a  statement  to declare a pointer  and initialize with your names.

    Ans. char name;
             char *cp;
             cp= &name;