Search Papers On This Blog. Just Write The Name Of The Course

Saturday 4 December 2010

CS201- Introduction to Programming Complete Solved Midterm Paper

MIDTERM  EXAMINATION
Spring 2010
CS201- Introduction to Programming (Session - 2)
Ref No: 1348086
Time: 60 min
Marks: 38
Student Info
 StudentID:
 
 Center:
 
 ExamDate:
 


Question No: 1    ( Marks: 1 )    - Please choose one
 In order to get 256 from the number 2568 we divide this number by 10 and take,
       ► Its remainder
       ► The number
       ► Its quotient
       ► Its divisor

Question No: 2    ( Marks: 1 )    - Please choose one
 The correct syntax of do-while loop is,
       ► (condition ) while; do { statements; };
       ► { statements; } do-while ();
       ► while(condition); do { statements; };
       ► do { statements; } while (condition);
   
Question No: 3    ( Marks: 1 )    - Please choose one
 Which of the following function(s) is/are included in stdlib.h header file?

       ► double atof(const char *nptr)
       ► int atoi(const char *nptr)
       ► char *strcpy ( char *s1, const char *s2)
       ► 1 and 2 only
   
Question No: 4    ( Marks: 1 )    - Please choose one
 If the break statement is missed in switch statement then,
       ► The compiler will give error
       ► This may cause a logical error
       ► No effect on program
       ► Program stops its execution
   
Question No: 5    ( Marks: 1 )    - Please choose one
 The data type before a function name represents its,
       ► Return Type
       ► Function data
       ► Function arguments
       ► Function name
   
Question No: 6    ( Marks: 1 )    - Please choose one
 Member function tellg() returns the current location of the ­­_____________ pointer.
       ► tellptr()

       ► write()

       ► seekg()

       ► get()


   
Question No: 7    ( Marks: 1 )    - Please choose one
 What does 5 | 6 , evaluate to in decimal where ‘|’ is bitwise OR operator?

►3
►4
►5
►7
   
Question No: 8    ( Marks: 1 )    - Please choose one
 C is widely known as development language of _______ operating system.
       ► Linux
       ► Windows
       ► Unix
       ► Mac OS
   
Question No: 9    ( Marks: 1 )    - Please choose one
 What will be the result of arithmetic expression 6+27/3*3?
       ► 33
       ► 45
       ► 9
       ► 30
   
Question No: 10    ( Marks: 1 )    - Please choose one
 How many bytes are occupied by declaring following array of characters?
 char str[] = “programming”;

       ► 10
       ► 11
       ► 12
       ► 13
   
Question No: 11    ( Marks: 1 )    - Please choose one
 What will be the correct syntax for initialization of pointer ptr with string "programming"?

       ► char ptr = ’programming’ ;

       ► char *ptr = “programming” ;

       ► char *ptr = ‘programming’ ;

       ► *ptr = “programming” ;


   
Question No: 12    ( Marks: 1 )    - Please choose one
 What will be the result of expression x%= 2, if x = 7?
►x = 1
►x = 3
►x = 7
►x = 2
   
Question No: 13    ( Marks: 1 )    - Please choose one
 UNIX has been developed in ________ language.
►JAVA
►B
►C
►FORTRAN
   
Question No: 14    ( Marks: 1 )    - Please choose one
 Declaring structures does not mean that memory is allocated.
►True
►False
   
Question No: 15    ( Marks: 1 )    - Please choose one
 What will be the value of i and j in the following code segment?
int i, j ;
int x[5] = {2, 3, 4, 8, 9} ;
int *ptr =&x[2];
i = (*ptr)++ ;
j = *ptr++ ;


►i = 5, j = 5
►i = 5, j = 8
►i = 4, j = 8
►i = 5, j = 9
   
Question No: 16    ( Marks: 1 )    - Please choose one
 When an array element is passed to a function, it is passed by ----------------.


► reference
► data type
► value
► data
   
Question No: 17    ( Marks: 2 )
 What is the difference between switch statement and if statement.
    Ans:The “switch” statement is use to slect among multiple alternatives.It uses many if statements to execute a particular case,while “if” statement is use to slect among two alternatives.

Question No: 18    ( Marks: 2 )
 Why we close a file after use?
      Ans:To execute the .exe file properly with latest changes.
   
Question No: 19    ( Marks: 2 )
 A two-dimensional array has 3 rows and 4 columns. Write down the syntax to initialize first element of all three rows of two-dimensional array with value 2.
Ans:
 int matrix[0][0]=2
 int matrix[1][0]=2
 int matrix[2][0]=2


  
Question No: 20    ( Marks: 3 )
 Identify the errors in the following code segment and give the reason of errors.
main(){
int x = 10
const int *ptr = &x ;
*ptr = 5 ;
}

Ans:
      Int x=10….No ending semicolon.
*ptr=5 .. Declaring a pointer to constant integer.You can not use this pointer to change the value being pointed to.
   
Question No: 21    ( Marks: 3 )
 Can you use an assignment operator to assign the value of one C-string to another?
Ans:Yes,we use assignment operator,whenever we use objects that allocate memory it is important that assignment operator should be defined for it,otherwise default operator will copy the value of addressed and pointers.
   

Question No: 22    ( Marks: 5 )
 Why binary search algorithm is more efficient than the linear search algorithm?
Ans:Binary search algorithm is more efficient than liner algorithem because the arrays are sorted in asending or desending order and we use “devide and conqrer” technique.In binery search each iteration reduces the search by the factor of two but in the linear we have the same number of searches as we have the number of elements.e.g,if we have array of 1000 elements the linear search will take 1000 iterations however binery search will take max 10.
   
Question No: 23    ( Marks: 5 )
 Write down the output of the code given below :
Hint:
Size of  char is 1 byte
Size of  int is 2 byte
Size of  float is 4 byte

#include <iostream.h>

union mytypes_t {
  char c;
  int i;
  float f;
  } mytypes;

int main(){
   
    mytypes.c = 'H';
    mytypes.i = 15;
   
    cout << sizeof(mytypes)<<endl;
   
    mytypes.i = 15;
    mytypes.c = 'H';
   
    cout << sizeof(mytypes)<<endl;
   
    system("PAUSE");
    return 0;
}

No comments:

Post a Comment