{"id":42344,"date":"2023-03-01T10:00:16","date_gmt":"2023-03-01T04:30:16","guid":{"rendered":"https:\/\/www.aplustopper.com\/?p=42344"},"modified":"2023-03-02T09:39:20","modified_gmt":"2023-03-02T04:09:20","slug":"plus-two-computer-science-chapter-wise-questions-and-answers-chapter-1","status":"publish","type":"post","link":"https:\/\/www.aplustopper.com\/plus-two-computer-science-chapter-wise-questions-and-answers-chapter-1\/","title":{"rendered":"Plus Two Computer Science Chapter Wise Questions and Answers Chapter 1 Structures and Pointers"},"content":{"rendered":"

Kerala Plus Two Computer Science Chapter Wise Questions and Answers Chapter 1 Structures and Pointers<\/h2>\n

Plus Two Computer Science Structures and Pointers One Mark Questions and Answers<\/h3>\n

Question 1.
\nName a method used to put logically related elements in one unit.
\nAnswer:
\nStructure or class<\/p>\n

Question 2.
\n…………… keyword is used to specify a structure.
\nAnswer:
\nstruct.<\/p>\n

Question 3.
\nState True or False.
\nAnswer:
\n\u2018A structure can be assigned to another structure only if both the structures are of same structure type\u2019.<\/p>\n

Question 4.
\nA structure brings together a group of
\n(a) Items of the same data type
\n(b) Integers with user defined names.
\n(c) Related data items and functions, if needed.
\n(d) None of the above
\nAnswer:
\n(c) Related data items and functions, if needed.<\/p>\n

Question 5.
\nPick the odd one out from the following.
\n(a) int
\n(b) struct
\n(c) char
\n(d) long
\nAnswer:
\n(b) struct<\/p>\n

Question 6.
\nSelect the structure member operator. Structure member operator select
\n(a) *
\n(b) .
\n(c) \u00ae
\n(d) [ ]
\nAnswer:
\n(b) .<\/p>\n

Question 7.
\nThe address of a computer memory starts at ………
\n(a) 0
\n(b) 1
\n(c) 1024
\n(d) none of these
\nAnswer:
\n(a) 0<\/p>\n

Question 8.
\nThe area used for dynamic memory allocation is called
\n(a) heap
\n(b) stack
\n(c) RAM
\n(d) Hard Disk
\nAnswer:
\n(a) heap<\/p>\n

Question 9.
\nGiven int *P, x = 35; P = &x; what is the value of *P?
\n(a) 34
\n(b) 35
\n(c) 0
\n(d) none of these
\nAnswer:
\n(b) 35<\/p>\n

Question 10.
\nint *P; p is having the address 2340. What will be the value of P after the execution of the statements P++; P = P – 3;
\n(a) 2340
\n(b) 2342
\n(c) 2338
\n(d) 2332
\nAnswer:
\n(d) 2332<\/p>\n

Question 11.
\nDynamic allocation means memory allocation at the time of ……….
\n(a) compilation
\n(b) debugging
\n(c) execution
\n(d) programming
\nAnswer:
\n(c) execution<\/p>\n

Question 12.
\nThe \u2018new\u2019 operator should be matched with a ……….
\n(a) pointer
\n(b) reference
\n(c) delete
\n(d) address
\nAnswer:
\n(c) delete<\/p>\n

Question 13.
\nIn the declaration void ff (int &, float &); the parameters are passed by …….
\n(a) reference
\n(b) value
\n(c) pointers
\n(d) default
\nAnswer:
\n(a) reference<\/p>\n

Question 14.
\nUsing ……… the memory location of a variable can be directly accessed and manipulated.
\nAnswer:
\nPointers.<\/p>\n

Question 15.
\nAnil argued that memory can be allocated as and when required during runtime. Do you agree with this opinion? Justify.
\nAnswer:
\nYes. Memory can be allocated during run time using the operator new.<\/p>\n

Question 16.
\nName the unary operator that returns the address of its operand.
\nAnswer:
\n& operator. Operator (Address operator)<\/p>\n

Question 17.
\nWhich among the following operators cannot be used with pointers?
\n(a) +
\n(b) –
\n(c) \/
\n(d) None of these
\nAnswer:
\n(c) \/<\/p>\n

Question 18.
\nThe address of the first byte is known as
\n(a) start
\n(b) Base address
\n(c) int address
\n(d) none of these
\nAnswer:
\n(b) Base address<\/p>\n

Question 19.
\nWhat are the free store operators?
\nAnswer:
\n\u2018new\u2019 and \u2018delete\u2019 operators.<\/p>\n

Question 20.
\nGive the syntax of new operator.
\nAnswer:
\n= new ;
\neg: int *P = new int;<\/p>\n

Question 21.
\nWhat does the following stmt mean?
\nint *P = new int [15];
\nAnswer:
\nAllocating memory for an integer array of 15 elements.<\/p>\n

Question 22.
\nThe ……. operator reverses the action of the \u2018new\u2019 operator.
\nAnswer:
\ndelete.<\/p>\n

Question 23.
\nWhich operator is used to access individual elements of a structure ora class while using pointer variables?
\nAnswer:
\n(a) *
\n(b) .
\n(c) ?
\n(d) None of these
\nAnswer:
\n(b) .<\/p>\n

Question 24.
\nA pointer is
\n(a) the address of a variable
\n(b) an indication of the variable to be accessed next
\n(c) a variable for storing addresses
\n(d) the datatype of an address variable
\nAnswer:
\n(c) a variable for storing addresses<\/p>\n

Question 25.
\nThe expression * test can be said to \u2018test
\n(a) be a pointer to test
\n(b) refer to the contents of test
\n(c) dereference test
\n(d) refer to the value of the variable pointed to by the test
\nAnswer:
\n(d) refer to the value of the variable pointed to by the test<\/p>\n

Question 26.
\nThe expression double * can be said to double*
\n(a) be a pointer pointing to variable double
\n(b) refer to contents of double
\n(c) be a pointer to a double type value
\n(d) refer to the value of the variable pointed to by double.
\nAnswer:
\n(c) be a pointer to a double type value<\/p>\n

Question 27.
\nThe new operator –
\n(a) returns a pointer to a variable
\n(b) creates a variable called new
\n(c) obtains memory for a new variable
\n(d) tells how much memory is available
\nAnswer:
\n(c) obtains memory for a new variable<\/p>\n

Question 28.
\nWrite a declaration for an array of 8 pointers to float float values
\n(a) float a []
\n(b) float*[*a] [8]
\n(c) float *a[8]
\n(d) float [*a][8]
\nAnswer:
\n(b) float*[*a] [8]<\/p>\n

Question 29.
\nA pointer to void can hold pointers to ………….
\n(a) void
\n(b) int
\n(c) float
\n(d) any data type
\nAnswer:
\n(d) any data type<\/p>\n

Question 30.
\nThe contents of two pointers that point to adjacent variable of type float differ by
\n(a) 4
\n(b) 2
\n(c) 1
\n(d) 8
\nAnswer:
\n(a) 4<\/p>\n

Question 31.
\nIn the …….. memory allocation, the amount of memory to be allocated is not known beforehand
\n(a) Static
\n(b) binding
\n(c) object
\n(d) dynamic
\nAnswer:
\n(d) dynamic<\/p>\n

Question 32.
\nImproper use of \u2018new\u2019 and \u2018delete\u2019 may lead to ….. \u2018new\u2019, \u2018delete\u2019 operator
\n(a) increase of memory
\n(b) memory leaks
\n(c) destruction of memory
\n(d) syntax errors
\nAnswer:
\n(b) memory leaks<\/p>\n

Question 33.
\nIf \u2018p\u2019 is pointer to the variable \u2018x\u2019, which of the following statement are correct.
\n(a) \u2018p\u2019 and \u2018x\u2019 may be of different data types
\n(b) if \u2018p\u2019 points to \u2018x\u2019, then \u2018x\u2019 also points to \u2018p\u2019
\n(c) the statement x = &p is valid
\n(d) *p will give the value of the variable \u2018x\u2019
\nAnswer:
\n(d) *p will give the value of the variable \u2018x\u2019<\/p>\n

Question 34.
\nSuppose \u2018m\u2019 is a float variable. Another variable \u2018ptr\u2019 stores the address of it, which is 2001. After the operation ptr++, it will point to the location having address ………. Why?
\n(a) 2002
\n(b) 2003
\n(C) 2004
\n(d) 2005
\nAnswer:
\n(d) 2005 (add the size of its data type, 2001 + 4)<\/p>\n

Question 35.
\nState True of False.
\n\u2018Only integers can be added or subtracted from pointers\u2019.
\nAnswer:
\nTrue<\/p>\n

Question 36.
\nGive the syntax for delete operator, delete operator
\nAnswer:
\ndelete pointer-variable;<\/p>\n

Question 37.
\nWhat does the following statement mean?
\ndelete [ ] marks;
\nAnswer:
\nDeallocating marks array<\/p>\n

Question 38.
\nName the operator that returns the data value stored in the area being pointed to by the pointer.
\nAnswer:
\n* Operator<\/p>\n

Question 39.
\nIf the name of an array is a pointer to its first ele\u00acment, how to move to third element.
\nAnswer:
\nArray name +2 gives the address of third element<\/p>\n

Question 40.
\nWhat does the following statement mean?
\nint * ptr [10];
\nAnswer:
\nAn array of 10 integer pointers<\/p>\n

Question 41.
\nState True of False.
\n\u2018It is faster to use an element pointer rather than an index when scanning arrays\u2019.
\nAnswer:
\nTrue.<\/p>\n

Question 42.
\nS[0] is not equal to S[0]
\n(a) *(S+0)
\n(b) *S
\n(c) *(s)
\n(d) S
\nAnswer:
\n(d) S<\/p>\n

Question 43.
\nWhich of the following declaration is valid?
\n(a) int*p = &a,
\n(b) int&p = *a,
\n(c) int &p = &a,
\n(d) int a = &p;
\nAnswer:
\n(a) int*p = &a,<\/p>\n

Question 44.
\n*p means ……….
\n(a) address of p
\n(b) value of p
\n(c) address of variable pointed to which p points
\n(d) value of virile to which p points
\nAnswer:
\n(a) address of p<\/p>\n

Question 45.
\n& p means ……..
\n(a) address of p
\n(b) value of p
\n(c) address of variable pointed to which p points
\n(d) value of variable to which p points
\nAnswer:
\n(a) address of p<\/p>\n

Question 46.
\nState True of False.
\n\u2018Only integers can be added or substracted from pointers\u2019.
\nAnswer:
\nTrue.<\/p>\n

Question 47.
\nRead the following statements:
\n(i) While defining a structure in C++, tag may be omitted.<\/p>\n

(ii) The data contained in a structure variable can be copied into another variable only if both of them are declared using the same structure tag.<\/p>\n

(iii) Elements of a structure is referenced by structure_name.element<\/p>\n

(iv) A structure can contain another structure.<\/p>\n

Now, Choose the correct option from the following:
\n(a) Statements (i) and (ii) are true
\n(b) Statements (ii) and (iv) are true
\n(e) Statements (i), (ii) and (iv) are true
\n(d) Statements (i) and (iii) are true
\nAnswer:
\n(d) Statements (i) and (iii) are true<\/p>\n

Question 48.
\nChoose the correct syntax for accessing a structure element.
\n(a) structure_name.element_name;
\n(b) element_name.structure_name;
\n(c) structure_variable.element_name;
\n(d) element_name.structure_variable;
\nAnswer:
\n(c) structure_variable.element_name;<\/p>\n

Question 49.
\nWhich one of the following is not correct about a pointer.
\nAnswer:
\n(a) A pointer stores address
\n(b) A Pointer stores L-value of a variable
\n(c) A Pointer points to a memory location
\n(d) A pointer stores R-Value of a variable
\nAnswer:
\n(d) A pointer stores R-Value of a variable<\/p>\n

Question 50.
\nThe following are some pointer variable declarations.
\n(a) float *ptr;
\n(b) int ptr*;
\n(c) short *ptr1,*ptr2;
\n(d) double ptr;
\nChoose the correct declaration
\n(i) a and b
\n(ii) a and c
\n(iii) a and d
\n(iv) a only
\nAnswer:
\n(ii) a and c<\/p>\n

Question 51.
\nThe address of operator (&) is used for
\n(a) Obtaining R-Value of a variable
\n(b) Obtaining L-Value of a variable
\n(c) Obtaining content of a variable
\n(d) None of these
\nAnswer:
\n(b) Obtaining L-Value of a variable<\/p>\n

Question 52.
\nDifferentiate static and dynamic memory allocation.
\nAnswer:
\nWhen the amount of memory to be allocated is known in advance and memory is allocated during compilation itself, it is referred to as static memory allocation. When the amount of memory to be allocated is not known in advance and it is required to allocate memory as and when required during run time, it is known as dynamic memory allocation.<\/p>\n

Question 53.
\nIf a memory allocated using the dynamic memory allocation operator new, is not deallocated using the operator delete, a problem occurs. Name that problem.
\nAnswer:
\nMemory leak<\/p>\n

Question 54.
\nThere is no chance of memory leak in static memory allocation\u201d. Say True\/False. Justify.
\nAnswer:
\nThe operating system takes the responsibility of memory allocation and deallocation without users instruction.<\/p>\n

Question 55.
\nWrite a C++ code segment to declare an integer pointer variable named p and store the address of an integer variable n into the pointer variable p.
\nAnswer:
\nint * p, n; p = &n;<\/p>\n

Question 56.
\nConsider the following code segment in C++. If a is stored at memory location 4020 and size of int is 4, then predict the output.
\nint *x, a;
\nx = &a;
\ncout << x ++ << \u201c\\n\u201d; .
\ncout << ++ x;
\nAnswer:
\n4020
\n4028<\/p>\n

Question 57.
\nChoose the operator which is not associated with a pointer variable.
\n(a) *
\n(b) .
\n(c) &
\n(d) \u2192
\nAnswer:
\n(b) .<\/p>\n

Question 58.
\nThe arrow (\u2192) operator is used for accessing
\n(a) structure element using structure variable.
\n(b) structure element using a structure name.
\n(c) structure element using structure pointer variable.
\n(d) structure element using structure tag.
\nAnswer:
\n(c) structure element using structure pointer variable.<\/p>\n

Question 59.
\nWrite a C++ statement to declare an array, using character pointer variable, which can store names of 60 students in a class.
\nAnswer:
\nchar*name[60];<\/p>\n

Question 60.
\nRead the following statements.
\n(i) A structure which contains another structure is called self referential structure.
\n(ii) A structure which, contains pointer to another structure is called self referential structure
\n(iii) A structure which contains another structure is called nested structure.
\n(iv) A structure which contains pointer to same structure is called self referential structure
\nNow, choose the correct option from the following
\n(a) statements (i) and (ii) are true
\n(b) statements (i) and (iii) are correct
\n(c) statements (ii) and (iii) are correct
\n(d) statements (iii) and (iv) are correct
\nAnswer:
\n(d) statements (iii) and (iv) are correct<\/p>\n

Question 61.
\nStructure is a …………………. data type.
\nFill up the blank by choosing correct option from the following.
\n(a) Fundamental
\n(b) Derived
\n(c) User defined
\n(d) Built in
\nAnswer:
\n(c) User defined<\/p>\n

Question 62.
\nWrite the declaration statement of a student structure variable named \u2018s\u2019 which is initialized with admission number 19, name as \u2018Aysha\u2019 and mark as 75.
\nAnswer:
\nstudent s = {19,\u201caysha”,75};<\/p>\n

Question 63.
\n\u201cThe dot(.) operator cannot be used for Recessing structure member by using structure pointer variable\u201d Say True or False. Justify your answer.
\nAnswer:
\nFalse. Arrow (\u2192) operator is used for accessing structure member by using structure pointer variable.<\/p>\n

Plus Two Computer Science Structures and Pointers Two Mark Questions and Answers<\/h3>\n

Question 1.
\nWrite C++ statement for the following.<\/p>\n

    \n
  1. To declare an integer variable named \u2018x\u2019 using new operator.<\/li>\n
  2. To initialize the integer pointer variable x with value 5.<\/li>\n
  3. To declare a dynamic array of ten integers named x.<\/li>\n<\/ol>\n

    Answer:<\/p>\n

      \n
    1. int*x = newint;<\/li>\n
    2. int*x = newint(5);<\/li>\n
    3. int *x = new int[10];<\/li>\n<\/ol>\n

      Question 2.
      \nConsider the following C++ program code to store address of an integer variable a into a pointer variable p
      \nint a = 5,*p;
      \nP = a;
      \ncout<< p;
      \nIdentify the error in the above program segment and correct the error.
      \nAnswer:
      \nP = a is the error because p is an integer pointer and can store only address. The correct code is p = &a;<\/p>\n

      Question 3.
      \nCorrect the program code given below:
      \nint a = 5;
      \nfloat *p;
      \np = &a;
      \ncout << p;
      \nAnswer:
      \nfloat*p; is to be corrected as int *p;
      \nor
      \nint a = 5; is to be corrected as float a = 5;<\/p>\n

      Question 4.
      \nCalculate the memory requirement for the following structure variable s1.
      \n[Consider the size of int = 4, char = 1 and float = 4]
      \nstruct student
      \n{
      \nint mo;
      \nchar name[25];
      \nfloat height;
      \n}s1;
      \nAnswer:
      \n\"Plus<\/p>\n

      Question 5.
      \nConsider the following array initialisation, int ar[5]={-2,-4,-6,2,4}; If first element of array is stored at 2050 and size of int is 4, find the output of the following.<\/p>\n

        \n
      1. cout<< *ar+*(ar+3);<\/li>\n
      2. cout<< ar+*(ar+4);<\/li>\n<\/ol>\n

        Answer:
        \n1.
        \n*ar = -2
        \n*(ar + 3) = 2 (fourth element)
        \nHence *ar + *(ar + 3) = -2 + 2 = 0
        \nHence output is 0<\/p>\n

        2.
        \nHere ar = 2050 (starting address)
        \nand * (ar + 4) = *(2050 + 4*4)
        \n= *(2050+16)
        \n= *(2066)
        \n= 4 (fifth element)
        \nHence ar + * (ar + 4)
        \n= 2050 + 4
        \n= 2054<\/p>\n

        Question 6.
        \nMatch the following:
        \n\"Plus
        \nAnswer:
        \na – iii
        \nb – iv
        \nc – ii
        \nd – i<\/p>\n

        Question 7.
        \nComplete the following table. The table is differentiating array and structure.
        \n\"Plus
        \nAnswer:
        \n\"Plus<\/p>\n

        Question 8.
        \nIdentify the errors in the following code fragment and correct it.
        \nstruct sample
        \n{
        \nint x;
        \nfloat y;
        \n} S1 ,S2;
        \nvoid main()
        \n{Struct test
        \nint a;
        \nfloat 6;
        \n}T1,T2;
        \nT1 = T2;
        \nT1=S1;
        \n}
        \nAnswer:
        \nThe assignment T1 = S1 is not correct. It is a variable of type test and S1 is a variable of type sample. So it cannot be assigned.<\/p>\n

        Question 9.
        \nWhen a C++ program is executed, the primary memory allocated for it is organized in a particular manner to deal with runtime memory allocation, function calls, variables, etc. Show a diagrammatic representation of it with brief explanation.
        \nAnswer:
        \nAfter compilation of C++ creates four distinct regions of memory used for distinct functions:<\/p>\n\n\n\n\n\n\n\n
        \n

        STACK 3<\/p>\n<\/td>\n<\/tr>\n

        \n

        HEAP 4<\/p>\n<\/td>\n<\/tr>\n

        Global<\/td>\nProgram<\/td>\n<\/tr>\n
        Variables<\/td>\nCode<\/td>\n<\/tr>\n
        2<\/td>\n1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

        The first area (1) is used for storing the compiled code of the program. The second area (2) is used for storing global variables of the program. It remains in memory till the program ends. The third region (3) known as the stack is used for holding the return addresses of function calls, arguments passed to the function, etc. The last region heap is used for dynamic allocation.<\/p>\n

        Question 10.
        \nAnalyze the following C++ statements and predict
        \nthe output.
        \nint k = 4 ;
        \nint *p ;
        \np = &k ;
        \ncout<< k ;
        \ncout<< *p;
        \ncout<< *p++ ;
        \ncout<< *(&k);
        \nAnswer:
        \n4, 4, 4, 4<\/p>\n

        Question 11.
        \nA boy wrote a C++ program that uses several pointer variables out of which some are used for dynamic allocation. He did not use the \u2018delete\u2019 operator anywhere in the program. While running the program, the computer got stuck up after some time. Predict the reason for this kind of situation, in connection with the above program code
        \nAnswer:
        \nThe situation is called memory leak. The memory allocated using \u2018new\u2019 should be properly deallocated using \u2018delete\u2019. If any function forgets to deallocate the memory using \u2018delete\u2019 which was allocated using the \u2018new\u2019 operator, it consumes some memory in every execution.<\/p>\n

        Thus a part of memory disappears with its every execution and it has some adverse effect on the system. This situation is called memory leak.<\/p>\n

        Question 12.
        \nIs there any difference between structure and array? Explain.
        \nAnswer:
        \nYes. An array can hold multiple elements of same datatype whereas a structure can hold multiple elements of different data types.<\/p>\n

        Question 13.
        \nWrite a C++ structure definition to store the student details given below:<\/p>\n

          \n
        1. Admission number<\/li>\n
        2. Name<\/li>\n
        3. Marks in six subjects<\/li>\n<\/ol>\n

          Answer:
          \nStruct student
          \n{
          \nintAdmno;
          \ncharname[30];
          \nint mark[6];
          \n}<\/p>\n

          Question 14.
          \nObserve the following layout of data,
          \n\"Plus<\/p>\n

            \n
          1. Name the data type in C++ used to represent the above data format.<\/li>\n
          2. Write the definition for implementing the above layout.<\/li>\n<\/ol>\n

            Answer:
            \n1. Structure<\/p>\n

            2. struct Account
            \n{
            \nint accno;
            \nchar name[30];
            \nstruct lastdate
            \n{
            \nint day;
            \nint month;
            \nint year;
            \n} tdate;
            \nfloat balanceamt;
            \n}<\/p>\n

            Question 15.
            \nConsider the following code segment.
            \nstruct student
            \n{
            \nint rollno;
            \nchar name[20];
            \nstruct date
            \n{
            \nint day;
            \nint month;
            \nint year;
            \n} birthday;
            \nchar batch[30];
            \nint score;
            \n}
            \nWrite valid statements in C++ to accept the name and date of birth of a student.
            \nAnswer:
            \ngets(S1 .name);
            \nS1.birthday.day=25;
            \nS1.birthday.month=5;
            \nS1.birthday. year=1991;<\/p>\n

            Question 16.
            \nWhy do we need structure variables, once a structure is defined in program?
            \nAnswer:
            \nStructure specification is merely a data type definition. Memory allocation does not take place during specification. To handle data, memory locations are needed. For memory allocation, variables are to be declared. Hence structure variable is essential for handling structured data in programs.<\/p>\n

            Question 17.
            \nWith an example explain how structures can be initialized.
            \nAnswer:
            \nStudent stud = {\u201cAthul\u201d, 17,101, \u201cXII Science\u201d};
            \nThe above statement initializes structure variable stud of type student which has data members name, age, roll no, batch.<\/p>\n

            Question 18.
            \nCan we declare a structure within another structure? Explain.
            \nYes. We can declare a structure as a member of another structure. It is known as nested structure.<\/p>\n

            Question 19.
            \nWhat does the following statement mean?
            \nAnswer:
            \nIt is accessing the element of a nested structure. S is a structure variable that contains another structure variable dob. \u2018month\u2019 is a member of inner structure variable dob. This statement assigns a value 10 to the member month.<\/p>\n

            Question 20.
            \nThomas says that name of an array is a pointer by default. Do you agree with him? Justify.
            \nAnswer:
            \nYes. C++ takes the array name as the address of its first element. That is, the name of an array is actually a pointer pointing to the first element of an array.<\/p>\n

            Question 21.
            \nDistinguish between
            \nint * ptr = new int (5);
            \nint * ptr = new int [5];
            \nAnswer:
            \nThe first statement allocates memory of one integer to ptr and initialized it with value 5. The second statement allocates memory of 5 contiguous integers (ie. an array of 5 integers) and stores begining address in pointer ptr.<\/p>\n

            Question 22.
            \nGive the syntax to declare an integer 2D array dy namically.
            \nAnswer:
            \nint * ptr = new int [m*n];
            \nwhere m and n are rows and columns<\/p>\n

            Question 23.
            \nThe array of character pointers is generally preferred over two dimensional array of characters. Justify.
            \nAnswer:
            \nThe array of character pointers is preferred. There are two reasons:
            \n1. An array of pointers makes more efficient use of available memory by consuming lesser number of bytes to store the strings.<\/p>\n

            2. An array of pointers makes the manipulation of the strings much easier. One can easily exchange the positions of the strings in the array of pointers without actually touching their memory locations.<\/p>\n

            Question 24.
            \nPredict the errors in the following code fragment in C++.
            \n1. float f= 1.42;
            \nfloat *a;
            \na = f;
            \n2. int *p,*q;
            \np = q + 1;
            \nAnswer:<\/p>\n

              \n
            1. a=&f is correct<\/li>\n
            2. No values assigned for p and q.<\/li>\n<\/ol>\n

              Question 25.
              \nDefine a structure in C++ to store book details such as book id, book name, price, and author name.
              \nAnswer:
              \nStructure is a group of different types of logically related data referenced by a single name,
              \nstruct book
              \n{
              \nint book id;
              \ncharbook_name[40];
              \nfloat price;
              \nchart author_name[40];
              \n};<\/p>\n

              Question 26.
              \nComplete the following structure definition, to store students details with appropriate values. Students details are roll number, name and height.
              \n\"Plus
              \nAnswer:
              \nstruct students
              \n{
              \nshort rno;
              \nchar name[25];
              \nfloat height;
              \n};<\/p>\n

              Question 27.
              \nCorrect the following structure definition to represent an employee with employee code, employee name, and salary.
              \nAnswer:
              \nEmployee struct
              \n{
              \necode int;
              \nchar name[25];
              \nsalary double;
              \n}<\/p>\n

              Question 28.
              \nConsider the array declaration. Assume that the first element of array is stored in 2020 location,
              \nint a[] = {2,5,8,9,4},*p1 ,*p2;
              \np1 = a;
              \np2 = &a[0];
              \ncout<< p1<< \u201c\\t\u201d<< p2;
              \nPredict the output and justify.
              \nAnswer:
              \np1 = a means, the array name is the starting address of an array.
              \nThat means p1 = 2020
              \np2 = &a[0] means p2 = 2020
              \nHence the output is 2020 2020<\/p>\n

              Plus Two Computer Science Structures and Pointers Three Mark Questions and Answers<\/h3>\n

              Question 1.
              \nExplain the type of structure defined below and calculate the number of bytes required to store the structure variable s1. [Considerthe size of int as 4 bytes and char as 1 byte]
              \nstruct student
              \n{
              \nint mo, mark;
              \nchar name[25];
              \nstruct date
              \n{
              \nint dd, mm, yy;
              \n}doj;
              \n}s1;
              \nAnswer:
              \nA structure contains another structure, then it is called nested structure.
              \n\"Plus<\/p>\n

              Question 2.
              \nDefine a structure to represent employee details. Employee details are employee code, employee name, date of joining and place of employee.
              \nAnswer:
              \nstruct employee
              \n{
              \nint empcode; ,
              \nchar name [40];
              \nstruct date
              \n{
              \nint day;
              \nint month;
              \nint year;
              \n}doj;
              \nchar place [40];
              \n};<\/p>\n

              Question 3.
              \n\u201cSelf referential structure can be used for implementing linked list\u201d. Justify the statement.
              \nAnswer:
              \nA structure contains an element that is a pointer to the same structure is called self referential structure. Eg: struct date {
              \nint dd, mm, yyyy;
              \ndate *ptr;
              \n};
              \nSo self referential structure can be used for implementing linked list.<\/p>\n

              Question 4.
              \nWrite a program in C++ to copy one string to another without using strcpy() function.
              \nAnswer:
              \n#include
              \nusing name space std; intmain()
              \n{
              \ncharstr [ ] = “computer”;
              \nchar * sptr;
              \nsptr = str;
              \ncout<< str<< endl;
              \ncout<< sptr<< endl;
              \n}
              \nThis code copies the string str to sptr;<\/p>\n

              Question 5.
              \nDefine a structure in C++ to store students\u2019 details such as admission number, name, address. Address contains house number, street name and city name.
              \nAnswer:
              \nStructure is a group of different types of logically related data referenced by a single name,
              \nstruct student
              \n{
              \nint adm_No;
              \nchar name[40];
              \nstruct
              \n{
              \nint house_no;
              \ncharstreet_name[40];
              \ncharcity_name[40];
              \n} address;
              \n};<\/p>\n

              Question 6.
              \nA structure variable can be declared along with structure definition.\u201d Justify this statement with an ex-ample.
              \nAnswer:
              \nYes, it is possible that, a structure variable can be declared along with structure definition itself.
              \nSyntax:
              \nstruct struet_name
              \n{
              \nData members;
              \n} structure variables;
              \nEg: struct date
              \n{
              \nintdd;
              \nint mm;
              \nintyyyy;
              \n}d1,d2,d3;<\/p>\n

              Question 7.
              \nIdentify and correct the error in the following code fragment.
              \nstruct first {
              \nint a; float b;
              \n}S1;
              \nstruct second {
              \nint a;
              \nfloat b;
              \n}S2;
              \nS1 = S2;
              \nAnswer:
              \nThe assignment S1 = S2 is not right. Because S1 and S2 are different structure variables. C++ does not permit different structure variable assignment.<\/p>\n

              Question 8.
              \nWrite structure definitions for structures containing the following.<\/p>\n

                \n
              1. book no, book name, price<\/li>\n
              2. item no, item name, price, monthly sales for last 4 months.<\/li>\n<\/ol>\n

                Answer:
                \n1. struct book
                \n{
                \nlong bookno;
                \nchar bookname[50];
                \nfloat price;
                \n};<\/p>\n

                2. struct item
                \n{
                \nint itemno;
                \nchar itemname[50];
                \nfloat price;
                \nint sale[4];
                \n}<\/p>\n

                Question 9.
                \nAssume that in a city, two football matches are going to be held. The coordinators of the match have decided to sell the tickets in two different styles. For the first match, the tickets will be sold one month in advance, but for the second one, tickets will be available from the stadium on the very same day of the match.<\/p>\n

                  \n
                1. Correlate this situation with the memory allocation techniques in C++.<\/li>\n
                2. Compare the merits and demerits of the two in relation with the given context.<\/li>\n<\/ol>\n

                  Answer:
                  \n1. Static and dynamic memory allocation.<\/p>\n

                  2. Every data and instruction data is being executed must be allocated some area in the main memory. The main memory can be allocated in two methods.<\/p>\n