134
Give the output of the programs in each case unless mentioned otherwise 1. void main() { int d=5; printf("%f",d); }Ans: Undefined 2. void main() { int i; for(i=1;i<4,i+ +) switch(i) case 1: printf("%d",i);break; { case 2:printf("%d",i);break; case 3:printf("%d",i);break; } switch(i) case 4:printf("%d",i); }Ans: 1,2,3,4 3. void main() { char *s="\12345s\n"; printf("%d",sizeof(s)); }Ans: 6 4. void main() { unsigned i=1; /* unsigned char k= -1 => k=255; */ signed j=-1; /* char k= -1 => k=65535 */ /* unsigned or signed int k= -1 =>k=65535 */ if(i<j) printf("less"); else if(i>j) printf("greater"); else if(i==j) printf("equal"); }Ans: less 5. void main() { float j; j=1000*1000; printf("%f",j); }

c,c++

Embed Size (px)

Citation preview

Page 1: c,c++

Give the output of the programs in each case unless mentioned otherwise

1. void main()

{

  int d=5;

  printf("%f",d);

}Ans: Undefined

2. void main()

{

  int i;

  for(i=1;i<4,i++)                                                                                 

  switch(i)

  case 1: printf("%d",i);break;

{

 case 2:printf("%d",i);break;

 case 3:printf("%d",i);break;

}

 switch(i) case 4:printf("%d",i);

}Ans: 1,2,3,4

3. void main()

{

 char *s="\12345s\n";

 printf("%d",sizeof(s));

}Ans: 6

4. void main()

{

  unsigned i=1; /* unsigned char k= -1 => k=255; */

  signed j=-1; /* char k= -1 => k=65535 */

/* unsigned or signed int k= -1 =>k=65535 */                                  

if(i<j)

  printf("less");

else

if(i>j)

  printf("greater");

else

if(i==j)

  printf("equal");

}Ans: less

5. void main()

{

  float j;

  j=1000*1000;

  printf("%f",j);

}

1. 1000000

2. Overflow

Page 2: c,c++

3. Error

4. None

Ans: 4

6. How do you declare an array of N pointers to functions returning  pointers to

functions returning pointers to characters?     Ans: The first part of this question can be

answered in at least        three ways:

7. Build the declaration up incrementally, using typedefs:

        typedef char *pc;    /* pointer to char */

        typedef pc fpc();    /* function returning pointer to char */

        typedef fpc *pfpc;    /* pointer to above */

        typedef pfpc fpfpc();    /* function returning... */

        typedef fpfpc *pfpfpc;    /* pointer to... */

        pfpfpc a[N];         /* array of... */

8. Use the cdecl program, which turns English into C and vice versa:          

        cdecl> declare a as array of pointer to function returning   pointer to function

returning pointer to char        char *(*(*a[])())()

cdecl can also explain complicated declarations, help with  casts, and indicate which

set of parentheses the arguments   go in (for complicated function definitions, like the

one   above).  Any good book on C should explain how to read these complicated   C

declarations "inside out" to understand them ("declaration mimics use"). The pointer-

to-function declarations in the examples above have not included parameter type

information. When the parameters have complicated types, declarations can *really*

get messy. (Modern versions of cdecl can help here, too.)

9. A structure pointer is defined of the type time . With 3 fields min,sec hours

having pointers to intergers.

    Write the way to initialize the 2nd element to 10.

10. In the above question an array of pointers is declared. Write the statement to

initialize the 3rd element of the 2 element to 10

11. int f()

void main()

{

  f(1);

  f(1,2);

  f(1,2,3);

}

f(int i,int j,int k)

{

  printf("%d %d %d",i,j,k);

}What are the number of syntax errors in the above?                     

Ans: None.

12. void main()

{

  int i=7;

  printf("%d",i++*i++);

}Ans: 56

Page 3: c,c++

13. #define one 0

#ifdef one 

printf("one is defined ");

#ifndef one

printf("one is not defined ");

Ans: "one is defined"

14. void main()

{

  intcount=10,*temp,sum=0;

  temp=&count;

  *temp=20;

  temp=&sum;

  *temp=count;

  printf("%d %d %d ",count,*temp,sum);

}

Ans: 20 20 20

15. There was question in c working only on unix machine with pattern matching.

16. what is alloca()   Ans : It allocates and frees memory after use/after getting out

of scope

17. main()

{

  static i=3;

  printf("%d",i--);

  return i>0 ? main():0;

}

Ans: 321

18. char *foo()

{

  char result[100]);

  strcpy(result,"anything is good");                                        

  return(result);

}

void main()

{

  char *j;

  j=foo()

  printf("%s",j);

}

Ans: anything is good.

19. void main()

{

  char *s[]={ "dharma","hewlett-packard","siemens","ibm"};

  char **p;

  p=s;

  printf("%s",++*p);

  printf("%s",*p++);

Page 4: c,c++

  printf("%s",++*p);

}Ans: "harma" (p->add(dharma) && (*p)->harma)

"harma" (after printing, p->add(hewlett-packard) &&(*p)->harma)

"ewlett-packard"

 

                               

Test Paper :1

Page 5: c,c++

 Paper Type     : Technical - C & C++

 Posted By        : adminpart

Page 6: c,c++

1 of paper 

first aptitude having five sections (50 question

Page 7: c,c++

s and 45 minutes) 

part 2 second c debugging (test ur c skill

Page 8: c,c++

s - yashwant kanitkar)(questions 20 time 30 min.) 

paper 1 

s

Page 9: c,c++

ection one 

15 questions (data sufficiency) a alone is suffic

Page 10: c,c++

ient b alone is sufficient a and b are both sufficient a and

Page 11: c,c++

b both are insufficient 

section two 

five questions (reading

Page 12: c,c++

comprehence ) very easy 

section three 

15 questions (logica

Page 13: c,c++

l reasoning) a pare is given and some hints are given u can fi

Page 14: c,c++

ne  out the ans 

one hotel has two zones (east and west)  not al

Page 15: c,c++

l east zone flats have ocean view but all weat zone flats have

Page 16: c,c++

harbour view  all ocean view flats has extra charge in harbour

Page 17: c,c++

view flats above and on 3rd floor have extra charge west zone

Page 18: c,c++

flats lower than 3rd floor some has kitchen so extra charge

Page 19: c,c++

all other flats of east zone not having ocean view has kitchen

Page 20: c,c++

so extra charges 

section four 

10 questions verbal reasoni

Page 21: c,c++

ng four or five sentences are given related to single topic  f

Page 22: c,c++

our options are given which are having order of  three sentenc

Page 23: c,c++

es(abe or bec)  select correct order 

sections five 

five comp

Page 24: c,c++

utational questions which were easy 

* total 12 members half ar

Page 25: c,c++

e in club a one third in b and one fourth in c how many are n

Page 26: c,c++

ot in any club ans 5(check) 

these type of questions u can fi

Page 27: c,c++

nd in R. S. Agrawal 

or IMS package of CAT 

in question it was w

Page 28: c,c++

ritten that all five sections carry their cutoffs so attempt a

Page 29: c,c++

ll but in electrical one guy was selected who didnot attempt re

Page 30: c,c++

ading comprehension but attempted all 45 questions this paper

Page 31: c,c++

also has negative marking of 50% 

paper 2 

1.what does p in c

Page 32: c,c++

onst char *p stands for p can be changed like this 

2.main() 

Page 33: c,c++

sturct date { char name[20]; int age ; float sal; }; sturct d

Page 34: c,c++

ata d ={"rajesh"}; printf("%d%f",d.age,d.sal); } tell the outp

Page 35: c,c++

ut 

3.main() int i=7; printf("%d"i++*i++); output 

4.void mai

Page 36: c,c++

n() { int d ; int i=10; d =sizeof(++i); printf("%d"); output 

Page 37: c,c++

5.difference between extern int f(); int f(); 

6.choose corr

Page 38: c,c++

ect (i)stack is automatically cleared (ii)heap is automatical

Page 39: c,c++

ly cleared (iii)user has to clear stack and heap (iv)system t

Page 40: c,c++

akes care of ---------- 

7. What'll be the output: main() {char

Page 41: c,c++

*a,*f(); a=f(); printf("%s",a); } char *f() {return("Hello W

Page 42: c,c++

orld"); 

8.What'll be the output: main() {char*a,*f(); a=char*

Page 43: c,c++

malloc(20*sizeof(char)); a=f(); printf("%s",a); } char *f() {

Page 44: c,c++

char n[20]; strcpy(n,"Hello World"); return(n); } 9.What is t

Page 45: c,c++

he error : main() {int j=10; switch(j) { case 20: pritnf("Les

Page 46: c,c++

s than 20"); break; case 30: printf("Less than 30"); break; d

Page 47: c,c++

efault: printf("hello"); } 

10.which is valid : (i)char arr[1

Page 48: c,c++

0]; arr="hello"; (ii) char arr[]="hello"; 

11. 

main() { char

Page 49: c,c++

*str; str=char*malloc(20*sizeof(char)); strcpy(str,"test"); s

Page 50: c,c++

trcat(str,'!'); printf("%s",str); } 

12. How many times main i

Page 51: c,c++

s get called : main() { printf("Jumboree"); main(); } ans: ti

Page 52: c,c++

ll stack overflow. 

13. Which statement is true about main : (i

Page 53: c,c++

) Varible no. of Arguments can be passed main. 

(ii) Main can b

Page 54: c,c++

e called from main(); (iii) We can't pass arguments are passe

Page 55: c,c++

d in main (iv) main always returns an int 

14. Output ? main()

Page 56: c,c++

 { int i,j; for(i=0,j=0;i<5,j<25;i++,j++); printf("%d %d",i,j

Page 57: c,c++

); } 

15.main() { int i; if(i=0) //it's assisnment not logica

Page 58: c,c++

l operator printf(" Hell "); else printf("Heaven"); like this n

Page 59: c,c++

o negative marking and more than one answers but paper I is cu

Page 60: c,c++

toff paper i think c paper will not be checked 

Interview 

th

Page 61: c,c++

ey will give u puzzles in first round which will be from site t

Page 62: c,c++

echinterview.org this site has 70 puzzles and their answers s

Page 63: c,c++

o go through them 

second round has c coding of data structur

Page 64: c,c++

e circular quese,tree etc also questions from c and c++ like

Page 65: c,c++

virtual functions far near huge memory concepts like heap,stac

Page 66: c,c++

k etc 

then in third round hr questions like hobbies and inte

Page 67: c,c++

rets make ur curriculam vite and bring it with ur file 

they

Page 68: c,c++

want people with good aptitude in interview rounds ur aptitud

Page 69: c,c++

e and approach matters so solve puzzles.    Enter Your Comments

Page 70: c,c++

Test Paper :1

 Paper Type     : Technical - C & C++

 Test Date        : 7  July  2003 

 Posted By        : admin

Ubinetics Test Pattern- July 2003

20 c objective Qs to be answered in 30 minutes All questions  are related to basic c concepts like expression, arrays, loops ,structure , pointers around 3 or 4 qs on array with loops  Since paper is very easy cutoff is very high.They will select 20% of the student for the interview after written test. Freshersworld.com point to remember.Each correct ans 1 marksEach wrong answer 1 -ve mark  Sample Paper           Some of the questions will not have answers .Please forgive us.  1. Difference b/n scanf("%s",msg);and scanf("%[\^n]",msg); where msg is a char array. 2. What is ure of comma operator in for loop.3. int shw(int *a){ *a = 10; /* return stmt is missing */}           main(){  int p=3,q=4;  q = shw(&p);  printf("%d %d",p,q);            }  4. which is true   a. all automatic variables are declared with in the function   b. all variables are automatic    c. all not declared variables are automatic    d. none   5. What is recursion. Recursive prog to generate Fibonacci series . Is it a best method?   6. write 7*a interms of +,-,<<   7. count number of 1's in a 32 bit integer.(i had not remembered whether array or integer). 8. main(){char *s1 = "hello",*s2 ="abce";strcpy(s1,"");             s2[0] = s1[0];   printf("%d%d",strlen(s1),strlen(s2)); } 9. regarding memset   10.Algorithm to delete a node in Double linked list.   11. Difference b/n fgets,fscanf which u will prefer.         Unix11.What is creon and whats diff b/n 'at' command.   12. what is system call and lib function. whats diff b/n them. abt execve - expalin.   13.some thing abt makeall   14. write abt TCP,IP,ICMP 

  Enter Your Comments                                 

Page 71: c,c++

Test Paper :2 Paper Type     : Technical - C & C++

 Posted By        : Madhav TRIAD 

mostly triad is only for mech guys only 

TRIAD PAPER 

C - language: 

1. write a program to calculate ncr 

2. write a program to exchange the values of two variables using pointers 

3. write program to open one file input some numbers and find smallest,largest, avg. and store them in another file. 

4. write a structure node using linked list 

5. write a program to reverse a string co-ordinate geometry 

1. find the perpendicular distance from a point P(a,b) to a line lx+my+n=0; 

2. y=x^3+2x^2+5x+2 find the slope of this eqn when x=12; 

( Hint :find dy/dx and substitute x=12) 

3. circle is x^2+y^2=a^2 . if the centre is shifted to (25,16) what is the eqn of new cirlce. 

4. pt rotation P(x,y) about origin in anticlockwise direction by an angle theta. find new coordinates.before this there will be some question on puzzles(gre barrons). 

prepare co-ordinate geometry and fundamental of c. 

  

regarding interview : 

1.they will ask whether u r interseted to go  aborad, 

ans:say no, not interested. 

2. tell some project works that r done and or 

Page 72: c,c++

going  to be do in c , c++, 

3. personal interview. 

4. be perfect in c, they r asking that how u done  this  in test  paper. 

5.they ask u do be agree to the company bond. bond  is for 3 years , breaking is at cost of 50,000. 

  

apptitude ; 

  some puzzles r given around 9, study well it is  easy,  for it they provide 20 min00110

                                 

Test Paper :2 Paper Type     : Technical - C & C++

 Posted By        : Mrudul Elico Questions

*16 ppl can do a work in 3 hrs?, how much time vil 5 ppl take?

* 185 miles. travelled in bus for 2 hrs a dist of 85. in how much time, he need to travel the ramaining 100 miles, if he need to get an average of 50 miles per hr.

*efface=? : similer word

* a 6 mtrs wide road is laid around a garden. rad area is 564sq mtsr. if the length of the garden is 20 mtrs?, wat is the width of it.

*Woman said pointing to a guy " his mother is the only daughter of my mother"

* a 2 digit no, the diff of its digits is one twelth of it. Find sum of the 2 digits-data insufficient-6-8-10-none

Cpp

* #includemain(){

Page 73: c,c++

int x=20, t;&t=x;x=50;cout<<x<<" "<<t;}o/p?

50 20t

-----*include<iostream.h>

int sum(int a, int b=5, int c=10);

main(){cout<<sum(5)<<endl<<sum(10,5)<<endl<<sum(5,10,10);}

int sum(int a, int b, int c){ return a+b+c;}

ans?20 25 25

------* #includemain(){int x=20, &t;&t=x;int &tt;cout<<x<<" "<<t;}o/p?

compile time error, as all references must b initialisded.------

what vil deleter operator vill do?- invoke delete operator, n then destructor- search if any destructor, n then invoke delete operasor.....-------What vil new operator vil do?

-invoke comnstructor, then new operator, then do typecasting-invoke new operator and then constructor-invoke constructor n do typecast....------which is violating data encapsulation?-friend-public-private-protected-virtual-------Friend fns are useful but r controversy bcoz,-they violate data encapsulation

Page 74: c,c++

-they access private fdata of a class-both-none of the above-------which of the following is true?//there are 4/5 q's in these format.

-a const member can't b changed...........-------

which of the following is false? in case of destructors, constructors............-------

what key word is used to off overload.- extern "C"-register "C"-static "C"-off "C"

------A,B,C,D,E,F are 6 members, facing the center of a circle.

A is btn B , EC btn D, fE is immediate right to D

q's on it   Enter Your Comments

1]. The following variable is available in file1.c static int average_float; all the functions in the file1.c can access the variable 

[2]. extern int x; Check the answer

[3]. Another Problem with  # define TRUE 0 some code while(TRUE){some code  } This won't go into the loop as TRUE is defined as 0 [4]. A question in structures where the memebers are dd,mm,yy. mm:dd:yy09:07:97

[5]. Another structure question  1 Rajiv System Analyst

[6]. INFILE.DAT is copied to OUTFILE.DAT 

[7]. A question with argc and argv .  Input will be

main(){

Page 75: c,c++

int x=10,y=15;x=x++;y=++y;printf("%d %d\n",x,y);} ----------------------------------------------------------------------

int x;main(){int x=0;{int x=10;x++;change_value(x);x++;Modify_value();printf("First output: %d\n",x);}x++;change_value(x);printf("Second Output : %d\n",x);Modify_value();printf("Third Output : %d\n",x);}

Modify_value(){return (x+=10);}

change_value(){return(x+=1);}

----------------------------------------------------------------------------

main(){int x=20,y=35;x = y++ + x++;y = ++y + ++x;printf("%d %d\n",x,y);}

----------------------------------------------------------------------- 

main(){char *p1="Name";char *p2;p2=(char *)malloc(20);while(*p2++=*p1++);printf("%s\n",p2);}---------------------------------------------------------------------- main(){int x=5;printf("%d %d %d\n",x,x<<2,x>>2);

Page 76: c,c++

}

--------------------------------------------------------------------

#define swap1(a,b) a=a+b;b=a-b;a=a-b;main(){int x=5,y=10;swap1(x,y);printf("%d %d\n",x,y);swap2(x,y);printf("%d %d\n",x,y);}

int swap2(int a,int b){int temp;temp=a;b=a;a=temp;return;}----------------------------------------------------------------------

main(){char *ptr = "Ramco Systems";(*ptr)++;printf("%s\n",ptr);ptr++;printf("%s\n",ptr);}

---------------------------------------------------------------------

#include<stdio.h>main(){char s1[]="Ramco";char s2[]="Systems";s1=s2;printf("%s",s1);}

----------------------------------------------------------------- 

#include<stdio.h>main(){char *p1;char *p2;p1=(char *) malloc(25);p2=(char *) malloc(25);strcpy(p1,"Ramco");strcpy(p2,"Systems");strcat(p1,p2);

Page 77: c,c++

printf("%s",p1);}                                  

Test Paper :2 Paper Type     : Technical - C & C++ Test Date        : 8  September  2005  Posted By        : Jai

TEXAS INSTRUMENTS PAPER - 08 SEP 2005Test Paper   01

1. Can we declare a static function as virtual?Ans: No. The virtual function mechanism is used on the specific object that determines which virtual function to call. Since the static functions are not any way related to objects, they cannot be declared as virtual.

2. Can user-defined object be declared as static data member of another class?Ans: Yes. The following code shows how to initialize a user-defined object.      #include      class test      {      int i ;      public :      test ( int ii = 0 )      {      i = ii ;      }      } ;      class sample      {      static test s ;      } ;      test sample::s ( 26 ) ;Here we have initialized the object s by calling the one-argument constructor. Wecan use the same convention to initialize the object by calling multiple-argument constructor.

3. What is forward referencing and when should it be used?Ans: Consider the following program:     class test      {      public :      friend void fun ( sample, test ) ;      } ;      class sample      {      public :      friend void fun ( sample, test ) ;      } ;      void fun ( sample s, test t )      {      // code      }      void main( )      {      sample s ;      test t ;      fun ( s, t ) ;

Page 78: c,c++

      }This program would not compile. It gives an error that sample is undeclared identifier in the statement friend void fun ( sample, test ) ; of the class test. This is so because the class sample is defined below the class test and we are using it before its definition. To overcome this error we need to give forward reference of the class sample before the definition of class test. The following statement is the forward reference of class sample. Forward referencing is generally required when we make a class or a function as a friend.

4. The istream_withassign class has been derived from the istream class and overloaded assignment operator has been added to it. The _withassign classes are much like their base classes except that they include overloaded assignment operators. Using these operators the objects of the _withassign classes can be copied. The istream, ostream, and iostream classes are made uncopyable by making their overloaded copy constructor and assignment operators private.

5. How do I write my own zero-argument manipulator that should work same as hex?Ans: This is shown in following program.      #include      ostream& myhex ( ostream &o )      {      o.setf ( ios::hex) ;      return o ;      }      void main( )      {      cout << endl << myhex << 2000 ;      }

6.We all know that a const variable needs to be initialized at the time of declaration. Then how come the program given below runs properly even when we have not initialized p?      #include      void main( )      {      const char *p ;      p = "A const pointer" ;      cout << p ;      }Ans: The output of the above program is 'A const pointer'. This is because in this program p is declared as 'const char*' which means that value stored at p will be constant and not p and so the program works properly

7. How do I refer to a name of class or function that is defined within a namespace?Ans: There are two ways in which we can refer to a name of class or function that is defined within a namespace: Using scope resolution operator through the using keyword. This is shown in following example:

      namespace name1     {      class sample1      {      // code      } ;      }      namespace name2      {      class sample2      {      // code

Page 79: c,c++

      } ;      }      using namespace name2 ;      void main( )      {      name1::sample1 s1 ;      sample2 s2 ;      }Here, class sample1 is referred using the scope resolution operator. On the other hand we can directly refer to class sample2 because of the statement using namespace name2 ; the using keyword declares all the names in the namespace to be in the current scope. So we can use the names without any qualifiers.

8. While overloading a binary operator can we provide default values?Ans: No!. This is because even if we provide the default arguments to the parameters of the overloaded operator function we would end up using the binary operator incorrectly. This is explained in the following example:

      sample operator + ( sample a, sample b = sample (2, 3.5f ) )      {      }      void main( )      {      sample s1, s2, s3 ;      s3 = s1 + ; // error      }

9. How do I carry out conversion of one object of user-defined type to another?Ans: To perform conversion from one user-defined type to another we need to provide conversion function. Following program demonstrates how to provide such conversion function.      class circle      {      private :      int radius ;      public:      circle ( int r = 0 )      {      radius = r ;      }      } ;      class rectangle      {      private :      int length, breadth ;      public :      rectangle( int l, int b )      {      length = l ;      breadth = b ;      }      operator circle( )      {      return circle ( length ) ;      }      } ;      void main( )      {      rectangle r ( 20, 10 ) ;

Page 80: c,c++

      circle c;      c = r ;      }Here, when the statement c = r ; is executed the compiler searches for an overloaded assignment operator in the class circle which accepts the object of type rectangle. Since there is no such overloaded assignment operator, the conversion operator function that converts the rectangle object to the circle object is searched in the rectangle class. We have provided such a conversion function in the rectangle class. This conversion operator function returns a circle object. By default conversion operators have the name and return type same as the object type to which it converts to. Here the type of the object is circle and hence the name of the operator function as well as the return type is circle.

10. How do I write code that allows to create only one instance of a class?Ans: This is shown in following code snippet.

      #include      class sample      {      static sample *ptr ;      private:      sample( )      {      }      public:      static sample* create( )      {      if ( ptr == NULL )      ptr = new sample ;      return ptr ;      }      } ;      sample *sample::ptr = NULL ;      void main( )      {      sample *a = sample::create( ) ;      sample *b = sample::create( ) ;      }Here, the class sample contains a static data member ptr, which is a pointerto the object of same class. The constructor is private which avoids us from creating objects outside the class. A static member function called create( ) is used to create an object of the class. In this function the condition is checked whether or not ptr is NULL, if it is then an object is created dynamically and its address collected in ptr is returned. If ptr is not NULL, then the same address is returned. Thus, in main( ) on execution of the first statement one object of sample gets created whereas on execution of second statement, b holds the address of the first object. Thus, whatever number of times you call create( ) function, only one object of sample class will be available.

11. How do I write code to add functions, which would work as get and put properties of a class?Ans: This is shown in following code.      #include      class sample      {      int data ;      public:      __declspec ( property ( put = fun1, get = fun2 ) )      int x ;      void fun1 ( int i )      {      if ( i < 0 )

Page 81: c,c++

      data = 0 ;      else      data = i ;      }      int fun2( )      {      return data ;      }      } ;      void main( )      {      sample a ;      a.x = -99 ;      cout << a.x ;      }Here, the function fun1( ) of class sample is used to set the given integer value into data, whereas fun2( ) returns the current value of data. To set these functions as properties of a class we have given the statement as shown below:__declspec ( property ( put = fun1, get = fun2 )) int x ;

As a result, the statement a.x = -99 ; would cause fun1( ) to get called to set the value in data. On the other hand, the last statement would cause fun2( ) to get called to return the value of data.

12. How do I write code to make an object work like a 2-D array?Ans: Take a look at the following program.      #include      class emp      {      public :      int a[3][3] ;      emp( )      {      int c = 1 ;      for ( int i = 0 ; i <= 2 ; i++ )      {      for ( int j = 0 ; j <= 2 ; j++ )      {      a[i][j] = c ;      c++ ;      }      }      }      int* operator[] ( int i )      {      return a[i] ;      }      } ;      void main( )      {      emp e ;      cout << e[0][1] ;      }The class emp has an overloaded operator [ ] function. It takes one argument an integer representing an array index and returns an int pointer. The statement cout << e[0][1] ; would get converted into a call to the overloaded [ ] function as e.operator[ ] ( 0 ). 0 would get collected in i. The function would return a[i] that represents the base address of the zeroeth row. Next the statement would get expanded as base address of zeroeth row[1] that can be further expanded as *( base address + 1 ). This gives us a value in zeroth row and first

Page 82: c,c++

column.

13. What are formatting flags in ios class?Ans: The ios class contains formatting flags that help users to format the stream data. Formatting flags are a set of enum definitions. There are two types of formatting flags:      On/Off flags      Flags that work in-groupThe On/Off flags are turned on using the setf( ) function and are turned off using the unsetf( ) function. To set the On/Off flags, the one argument setf( ) function is used. The flags working in groups are set through the two-argument setf( ) function. For example, to left justify a string we can set the flag as,      cout.setf ( ios::left ) ;      cout << "KICIT Nagpur" ;      To remove the left justification for subsequent output we can say,      cout.unsetf ( ios::left ) ;The flags that can be set/unset include skipws, showbase, showpoint,uppercase, showpos, unitbuf and stdio. The flags that work in a group can have only one of these flags set at a time.

14. What is the purpose of ios::basefield in the following statement?      cout.setf ( ios::hex, ios::basefield ) ;Ans: This is an example of formatting flags that work in a group. There is a flag for each numbering system (base) like decimal, octal and hexadecimal. Collectively, these flags are referred to as basefield and are specified by ios::basefield flag. We can have only one of these flags on at a time. If we set the hex flag as setf ( ios::hex ) then we will set the hex bit but we won't clear the dec bit resulting in undefined behavior. The solution is to call setf( ) as setf ( ios::hex, ios::basefield ). This call first clears all the bits and then sets the hex bit.

15. Can we get the value of ios format flags?Ans: Yes! The ios::flags( ) member function gives the value format flags. This function takes no arguments and returns a long ( typedefed to fmtflags) that contains the current format flags.

16. Is there any function that can skip certain number of characters present in the input stream?Ans: Yes! This can be done using cin::ignore( ) function. The prototype of this function is as shown below:      istream& ignore ( int n = 1, int d =EOF ) ;Sometimes it happens that some extra characters are left in the input stream while taking the input such as, the ?\n? (Enter) character. This extra character is then passed to the next input and may pose problem.

To get rid of such extra characters the cin::ignore( ) function is used. This is equivalent to fflush ( stdin ) used in C language. This function ignores the first n characters (if present) in the input stream, stops if delimiter d is encountered.

17. Write a program that implements a date class containing day, month and year as data members. Implement assignment operator and copy constructor in this class.Ans: This is shown in following program:      #include      class date      {      private :      int day ;      int month ;      int year ;      public :      date ( int d = 0, int m = 0, int y = 0 )

Page 83: c,c++

      {      day = d ;      month = m ;      year = y ;      }      // copy constructor      date ( date &d )      {      day = d.day ;      month = d.month ;      year = d.year ;      }      // an overloaded assignment operator      date operator = ( date d )      {      day = d.day ;      month = d.month ;      year = d.year ;      return d ;      }      void display( )      {      cout << day << "/" << month << "/" << year ;      }      } ;      void main( )      {      date d1 ( 25, 9, 1979 ) ;      date d2 = d1 ;      date d3 ;      d3 = d2 ;      d3.display( ) ;      }

18. When should I use unitbuf flag?Ans: The unit buffering (unitbuf) flag should be turned on when we want to ensure that each character is output as soon as it is inserted into an output stream. The same can be done using unbuffered output but unit buffering provides a better performance than the unbuffered output.

19.What are manipulators?Ans: Manipulators are the instructions to the output stream to modify the output in various ways. The manipulators provide a clean and easy way for formatted output in comparison to the formatting flags of the ios class. When manipulators are used, the formatting instructions are inserted directly into the stream. Manipulators are of two types, those that take an argument and those that don?t.

20. What is the difference between the manipulator and setf( ) function?Ans: The difference between the manipulator and setf( ) function are as follows:

The setf( ) function is used to set the flags of the ios but manipulators directly insert the formatting instructions into the stream. We can create user-defined manipulators but setf( ) function uses data members of ios class only. The flags put on through the setf( ) function can be put off through unsetf( ) function. Such flexibility is not available with manipulators.

21. How do I get the current position of the file pointer?Ans: We can get the current position of the file pointer by using the tellp( ) member function of ostream class or tellg( ) member function of istream class. These functions return (in

Page 84: c,c++

bytes) positions of put pointer and get pointer respectively.

22. What are put and get pointers?Ans: These are the long integers associated with the streams. The value present in the put pointer specifies the byte number in the file from where next write would take place in the file. The get pointer specifies the byte number in the file from where the next reading should take place.

23. What do the nocreate and noreplace flag ensure when they are used for opening a file?Ans: nocreate and noreplace are file-opening modes. A bit in the ios class defines these modes. The flag nocreate ensures that the file must exist before opening it. On the other hand the flag noreplace ensures that while opening a file for output it does not get overwritten with new one unless ate or app is set. When the app flag is set then whatever we write gets appended to the existing file. When ate flag is set we can start reading or writing at the end of existing file.

24. What is the limitation of cin while taking input for character array?Ans: To understand this consider following statements,      char str[5] ;      cin >> str ;While entering the value for str if we enter more than 5 characters then there is no provision in cin to check the array bounds. If the array overflows, it may be dangerous. This can be avoided by using get( ) function. For example, consider following statement,      cin.get ( str, 5 ) ;On executing this statement if we enter more than 5 characters, then get( ) takes only first five characters and ignores rest of the characters. Some more variations of get( ) are available, such as shown below:      get ( ch ) ? Extracts one character only      get ( str, n ) ? Extracts up to n characters into str      get ( str, DELIM ) ? Extracts characters into array str until specified delimiter (such as '\n'). Leaves delimiting character in stream.      get ( str, n, DELIM ) ? Extracts characters into array str until n characters or DELIM character, leaving delimiting character in stream.

25. What is the purpose of istream class? Ans: The istream class performs activities specific to input. It is derived from the ios class. The most commonly used member function of this class is the overloaded >> operator which can extract values of all basic types. We can extract even a string using this operator.

26. Would the following code work?      #include      void main( )      {      ostream o ;      o << "Dream. Then make it happen!" ;      }Ans: No! This is because we cannot create an object of the ostream class since its constructor and copy constructor are declared private.

27. Can we use this pointer inside static member function?Ans: No! The this pointer cannot be used inside a static member function. This is because a static member function is never called through an object.

28. What is strstream?Ans: strstream is a type of input/output stream that works with the memory. It allows using section of the memory as a stream object. These streams provide the classes that can be used for storing the stream of bytes into memory. For example, we can store integers, floats and strings as a stream of bytes. There are several classes that implement this in-memory

Page 85: c,c++

formatting. The class ostrstream derived from ostream is used when output is to be sent to memory, the class istrstream derived from istream is used when input is taken from memory and strstream class derived from iostream is used for memory objects that do both input and output.  Ans: When we want to retrieve the streams of bytes from memory we can use istrestream. The following example shows the use of istrstream class.      #include      void main( )      {      int age ;      float salary ;      char name[50] ;      char str[] = "22 12004.50 K. Vishwanatth" ;      istrstream s ( str ) ;      s >> age >> salary >> name ;      cout << age << endl << salary << endl << name ;      cout << endl << s.rdbuf( ) ;      }Here, s is the object of the class istrstream. When we are creating the object s, the constructor of istrstream gets called that receives a pointer to the zero terminated character array str. The statement s >> age >> salary >> name ; extracts the age, salary and the name from the istrstream object s. However, while extracting the name, only the first word of name gets extracted. The balance is extracted using rdbuf( ).

29. When the constructor of a base class calls a virtual function, why doesn't the override function of the derived class gets called?Ans: While building an object of a derived class first the constructor of the base class and then the constructor of the derived class gets called. The object is said an immature object at the stage when the constructor of base class is called. This object will be called a matured object after the execution of the constructor of the derived class. Thus, if we call a virtual function when an object is still immature, obviously, the virtual function of the base class would get called. This is illustrated in the following example.      #include      class base      {      protected :      int i ;      public :      base ( int ii = 0 )      {      i = ii ;      show( ) ;      }      virtual void show( )      {      cout << "base's show( )" << endl ;      }      } ;      class derived : public base      {      private :      int j ;      public :      derived ( int ii, int jj = 0 ) : base ( ii )      {      j = jj ;      show( ) ;      }      void show( )      {      cout << "derived's show( )" << endl ;

Page 86: c,c++

      }      } ;

      void main( )      {      derived dobj ( 20, 5 ) ;      }      The output of this program would be:      base's show( )      derived's show( )

30. Can I have a reference as a data member of a class? If yes, then how do I initialise it?Ans: Yes, we can have a reference as a data member of a class. A reference as a data member of a class is initialized in the initialization list of the constructor. This is shown in following program.      #include      class sample      {      private :      int& i ;      public :      sample ( int& ii ) : i ( ii )      {      }      void show( )      {      cout << i << endl ;      }      } ;      void main( )      {      int j = 10 ;      sample s ( j ) ;      s.show( ) ;      }Here, i refers to a variable j allocated on the stack. A point to note here is that we cannot bind a reference to an object passed to the constructor as a value. If we do so, then the reference i would refer to the function parameter (i.e. parameter ii in the constructor), which would disappear as soon as the function returns, thereby creating a situation of dangling reference.

31. Why does the following code fail?      #include      class sample      {      private :      char *str ;      public :      sample ( char *s )      {      strcpy ( str, s ) ;      }      ~sample( )      {      delete str ;      }      } ;      void main( )      {      sample s1 ( "abc" ) ;

Page 87: c,c++

      }Ans: Here, through the destructor we are trying to deal locate memory, which has been allocated statically. To remove an exception, add following statement to the constructor.      sample ( char *s )      {      str = new char[strlen(s) + 1] ;      strcpy ( str, s ) ;      }Here, first we have allocated memory of required size, which then would get deal located through the destructor.

32. assert( ) macro...We can use a macro called assert( ) to test for conditions that should not occur in a code. This macro expands to an if statement. If test evaluates to 0, assert prints an error message and calls abort to abort the program.      #include      #include      void main( )      {      int i ;      cout << "\nEnter an integer: " ;      cin >> i ;      assert ( i >= 0 ) ;      cout << i << endl ;      }

33. Why it is unsafe to deal locate the memory using free( ) if it has beenallocated using new?Ans: This can be explained with the following example:      #include      class sample      {      int *p ;      public :      sample( )      {      p = new int ;      }      ~sample( )      {      delete p ;      }      } ;      void main( )      {      sample *s1 = new sample ;      free ( s1 ) ;      sample *s2 = ( sample * ) malloc ( sizeof ( sample ) ) ;      delete s2 ;      }The new operator allocates memory and calls the constructor. In the constructor we have allocated memory on heap, which is pointed to by p. If we release the object using the free( ) function the object would die but the memory allocated in the constructor would leak. This is because free( ) being a C library function does not call the destructor where we have deal located the memory.

As against this, if we allocate memory by calling malloc( ) the constructor would not get called. Hence p holds a garbage address. Now if the memory is deal located using delete, the destructor would get called where we have tried to release the memory pointed to by p. Since

Page 88: c,c++

p contains garbage this may result in a runtime error.

34. Can we distribute function templates and class templates in object libraries?Ans: No! We can compile a function template or a class template into object code (.obj file). The code that contains a call to the function template or the code that creates an object from a class template can get compiled. This is because the compiler merely checks whether the call matches the declaration (in case of function template) and whether the object definition matches class declaration (in case of class template). Since the function template and the class template definitions are not found, the compiler leaves it to the linker to restore this. However, during linking, linker doesn't find the matching definitions for the function call or a matching definition for object creation. In short the expanded versions of templates are not found in the object library. Hence the linker reports error.

35. What is the difference between an inspector and a mutator ?Ans: An inspector is a member function that returns information about an object's state (information stored in object's data members) without changing the object's state. A mutator is a member function that changes the state of an object. In the class Stack given below we have defined a mutator and an inspector.      class Stack      {      public :      int pop( ) ;      int getcount( ) ;      }In the above example, the function pop( ) removes top element of stack thereby changing the state of an object. So, the function pop( ) is a mutator. The function getcount( ) is an inspector because it simply counts the number of elements in the stack without changing the stack.

36. Namespaces:The C++ language provides a single global namespace. This can cause problems with global name clashes. For instance, consider these two C++ header files:      // file1.h      float f ( float, int ) ;      class sample { ... } ;      // file2.h      class sample { ... } ;With these definitions, it is impossible to use both header files in a single program; the sample classes will clash. A namespace is a declarative region that attaches an additional identifier to any names declared inside it. The additional identifier thus avoids the possibility that a name will conflict with names declared elsewhere in the program. It is possible to use the same name in separate namespaces without conflict even if the names appear in the same translation unit. As long as they appear in separate namespaces, each name will be unique because of the addition of the namespace identifier. For example:     // file1.h      namespace file1      {      float f ( float, int ) ;      class sample { ... } ;      }      // file2.h      namespace file2      {      class sample { ... } ;      }

Now the class names will not clash because they become file1::sample and file2::sample,

Page 89: c,c++

respectively.

37. What would be the output of the following program?      #include      class user      {      int i ;      float f ;      char c ;      public :      void displaydata( )      {      cout << endl << i << endl << f << endl << c ;      }      } ;      void main( )      {      cout << sizeof ( user ) ;      user u1 ;      cout << endl << sizeof ( u1 ) ;      u1.displaydata( ) ;      }Ans: The output of this program would be,      9 or 7      9 or 7      Garbage      Garbage      GarbageSince the user class contains three elements, int, float and char its size would be 9 bytes (int-4, float-4, char-1) under Windows and 7 bytes (int-2, float-4, char-1) under DOS. Second output is again the same because u1 is an object of the class user. Finally three garbage values are printed out because i, f and c are not initialized anywhere in the program.

Note that if you run this program you may not get the answer shown here. This is because packing is done for an object in memory to increase the access efficiency. For example, under DOS, the object would be aligned on a 2-byte boundary. As a result, the size of the object would be reported as 6 bytes. Unlike this, Windows being a 32-bit OS the object would be aligned on a 4-byte boundary. Hence the size of the object would be reported as 12 bytes. To force the alignment on a 1-byte boundary, write the following statement before the class declaration.     #pragma pack ( 1 )

38. Write a program that will convert an integer pointer to an integer and vice-versa. Ans: The following program demonstrates this.      #include      void main( )      {      int i = 65000 ;      int *iptr = reinterpret_cast ( i ) ;      cout << endl << iptr ;      iptr++ ;      cout << endl << iptr ;      i = reinterpret_cast ( iptr ) ;      cout << endl << i ;      i++ ;      cout << endl << i ;      }

39. What is a const_cast?

Page 90: c,c++

Ans. The const_cast is used to convert a const to a non-const. This is shown in the following      program:      #include      void main( )      {      const int a = 0 ;      int *ptr = ( int * ) &a ; //one way      ptr = const_cast_ ( &a ) ; //better way      }Here, the address of the const variable a is assigned to the pointer to a non-const variable. The const_cast is also used when we want to change the data members of a class inside the const member functions. The following code snippet shows this:      class sample      {      private:      int data;      public:      void func( ) const      {      (const_cast (this))->data = 70 ;      }      } ;

40. What is forward referencing and when should it be used?Ans: Forward referencing is generally required when we make a class or a function as a friend.Consider following program:      class test      {      public:      friend void fun ( sample, test ) ;      } ;      class sample      {      public:      friend void fun ( sample, test ) ;      } ;      void fun ( sample s, test t )      {      // code      }      void main( )      {      sample s ;      test t ;      fun ( s, t ) ;      }On compiling this program it gives error on the following statement of test class. It gives an error that sample is undeclared identifier. friend void fun ( sample, test );This is so because the class sample is defined below the class test and we are using it before its definition. To overcome this error we need to give forward reference of the class sample before the definition of class test. The following statement is the forward reference of class sample.      class sample ;

41. How would you give an alternate name to a namespace?Ans: An alternate name given to namespace is called a namespace-alias. namespace-alias is generally used to save the typing effort when the names of namespaces are very long or complex. The following syntax is used to give an alias to a namespace.

Page 91: c,c++

      namespace myname = my_old_very_long_name ;

42. Using a smart pointer can we iterate through a container?Ans: Yes. A container is a collection of elements or objects. It helps to properly organize and store the data. Stacks, linked lists, arrays are examples of containers. Following program shows how to iterate through a container using a smart pointer.      #include      class smartpointer      {      private :      int *p ; // ordinary pointer      public :      smartpointer ( int n )      {      p = new int [ n ] ;      int *t = p ;      for ( int i = 0 ; i <= 9 ; i++ )      *t++ = i * i ;      }      int* operator ++ ( int )      {      return p++ ;      }      int operator * ( )      {      return *p ;      }      } ;      void main( )      {      smartpointer sp ( 10 ) ;      for ( int i = 0 ; i <= 9 ; i++ )      cout << *sp++ << endl ;      }Here, sp is a smart pointer. When we say *sp, the operator * ( ) function gets called. It returns the integer being pointed to by p. When we say sp++ the operator ++ ( ) function gets called. It increments p to point to The next element in the array and then returns the address of this new location.

43. Can objects read and write themselves?Ans: Yes! This can be explained with the help of following example:      #include      #include      class employee      {      private :      char name [ 20 ] ;      int age ;      float salary ;      public :      void getdata( )      {      cout << "Enter name, age and salary of employee : " ;      cin >> name >> age >> salary ;      }      void store( )      {      ofstream file ;      file.open ( "EMPLOYEE.DAT", ios::app | ios::binary ) ;

Page 92: c,c++

      file.write ( ( char * ) this, sizeof ( *this ) ) ;      file.close( ) ;      }      void retrieve ( int n )      {      ifstream file ;      file.open ( "EMPLOYEE.DAT", ios:

 

 

1. Which of the following best explains life cycle of Defect ?

 a) Defect Found -> Defect Logged -> Defect Debugged -> Defect Closed -> Defect Rechecked 

 b) Defect Found -> Defect Debugged -> Defect Reported -> Defect Rechecked -> DefectClosed

 c) Defect Debugged -> Defect Found -> Defect Closed -> Defect Reported -> DefectRechecked

 d) Defect Found -> Defect Logged -> Defect Debugged -> Defect Rechecked -> Defect Closed

2. Which group does Winrunner ,Load Runner ,SQA Suite fall under ?

  a) Databases

  b) Automated Test Tools

  c) Operating   Systems

  d) Rapid Application Development Tool3.  i = 0;

j = 0;

for(j=1;j<10;j++)

i=i+1; In the (generic) code segment above what will be the value of the variable i at completion ?

    a) 0

    b) 1

    c) 3

    d) 94. Which of the following statements is true when a derivation inherits both a virtual and

non-virtual instance of a base class ?

    a) Each derived class object has base objects only from the non virtual instance

    b) Each base class object has derived objects only from the non-virtual instance 

Page 93: c,c++

    c) Each derived class object has base objects only from the virtual instance

    d) Each derived class object has a base object from the virtual instance and a base object from non-virtual instance.

5.  class Word

    {

     public: 

     Word(const char*,int = 0);

  };

Referring to the sample code above what is the minimum number of arguments required to call the constructor ?

    a) 0

    b) 1

    c) 2

    d) 36. Which one of the following represents a correct and safe declaration of NULL ?

a) typedef((void *)0) NULL;

b) typedef NULL(char *)0;

c) #define NULL((void *)0)

d) #define NULL((char*)0)7. #include <iostraem>

Referring to the sample code above ,which of the following could you use to make the standars I/O Stream classes accessible without requiring the scope resolution operator ?

  a) using namespace std::iostream

  b) using namespace std;

  c) using namespace iostream ;

  d) using iostream;8. Which one of the following statements allocates enough space to hold an array of 10

integers that are initialized to 0 ?

  a) int *ptr = (int *) calloc(10,sizeof(int));

  b) int *ptr = (int *) alloc( 10*sizeof(int));

  c) int *ptr = (int *) malloc( 10*sizeof(int));

  d) int *ptr = (int *)calloc(10*sizeof(int));9. What function will read a specified number of elements from a file ?

  a) fread()

Page 94: c,c++

  b) readfile()

  c) fileread()

  d) gets()10. What is the largest value an integer can hold in a Standard C compiler ?

  a) 32767

  b) 65536

  c) 2147483647

  d) INT_MAX11. With every use of memory allocation function should be used to release allocated

memory which is no longer needed ?

  a) dropmem()

  b) dealloc()

  c) release()

  d) free()12.  int a=1;

 int ab=4;

 int main()

    {

     int b=3,a=2;

     printf("%i*/%i*/%*/i",a,b,ab); 

   }13.  kernal execute the first process when system is start---

 ans :- init();14. process id of kernal

  (a) 1

  (b) 0

  (c) 2

  (d) none15.  Which one of the following represents a correct and safe declaration of NULL ?

  a) typedef((void *)0) NULL;

  b) typedef NULL(char *)0;

  c) #define NULL((void *)0)

  d) #define NULL((char*)0)16. Which one of the following statements allocates enough space to hold an array of 10

integers that are initialized to 0 ?

Page 95: c,c++

  a) int *ptr = (int *) calloc(10,sizeof(int));

  b) int *ptr = (int *) alloc( 10*sizeof(int));

  c) int *ptr = (int *) malloc( 10*sizeof(int));

  d) int *ptr = (int *)calloc(10*sizeof(int));.

After written ,group discussion and interview will be there

Topics for group discussion:

1. Is IT sector made a difference to rural India.2. Does the world need army?3. are there stars in the sky?4. capital punishment should be avoided .5. Is India really shining ?

 Directions: Each of the following question has a question and two statements labelled as (i) and (ii). Use the data/information given in (i) and (ii) to decide whether the data are sufficient to answer the question record your answer as

A) If you can get the answer from (1)alone but not from (2)B) If you can get the answer from (2)alone but not from (1)C) If can get the answer from (1)and (2)together ,although neither statement by itself sufficeD) If statement (1)alone suffices and statement (2) alone also suffice.E) If can't get the answer from statements (1) and (2) together and you need more data.

1. What will be the population of city X in 1991?

1) Population of the city has 55% annual growth rate

2) in 1991,the population of city X was 8 million

Ans:C

2. Was it Rani's birthday yesterday?

1)Lata spends Rs.100 on Rani's birthday

2)Lata spent Rs.100 yesterdayAns: E

3. Is 3*5 or is 4*6 greater ?

1) a*b =b*a 

2) a*b is the remainder of ab%(a+b)

Ans:B

4. Will the graph X-Y pass through the origin?

1) x proportional to the Y

2)increment in y per units rise of x is fixed.

Ans:E

5. What was the value of the machine 2 years ago?

Page 96: c,c++

1) the deprecition of the value of the machine per year is 10%2)present value of the machine is rs 8000/

Ans:C

6. What will be the area of a square that can be inscribed in a circle?

1) Radius of the circle is T

2) Length of a diagonal of the square is 2r

Ans:D

7. There are two figures viz., a circle and a square. Which having greater area?

1) Perimeter of the circle is the same as the perimeter of the square.

2) Eleven times the radius is equal to seven times the length of one side of the square.

Ans: D

8. A candidate who was found to be under weightin medical test had been selected

provisionally subject to his attainment of 60Kg weight within one year. What should be

the percentage increase of his weightso that selection is confirmed after one year.

1) Weight (Kg)=16+8 Height (ft) is standard equation for the Indian population. The

candidates height is 5.5

2) His present weight is 55Kg.

Ans: D

9. Is angle µ=90

1) sin**2(µ)+cos**2(µ)=1

2) sin**2(µ)-+cos**2(µ)=1

Ans: E

10. What will be the average age of workers of an Institution after two years?

1) Present average age is 35 years

2) There are total 20 workers in the Institution                                     

 Ans: A

11. Is AB>AM ( A Triangle is given )

1) AB<AC

2) M is any point other than B and C on BC

Ans: E

12. Is X^2+Y^2<X+Y?

1) 0<X<1

2) 0<Y<1 and X!=Y (X not equal to Y)

Ans: C

13. Can it be concluded that angle ABO = angle ODC

1) ABCD is a Parallelogram and O is the point of intersection of the diagonals.

2) Angle DOC =75deg. and angle DAO =35deg.

Ans: A

Page 97: c,c++

14. What is the value of x+y?

1) 2y=x+6

2) 5x=10y-30

Ans: E

15. How many students are there in the class?

1) 30 students play foot ball and 40 play cricket .

2)Each student plays either foot ball or cricket or both.

Ans: E

16. What is the value of a:b?

1) a=x+10%ofx

2) b=a+10%ofa

Ans: B

17. What is the maximum value of the expression 5+8x-8x^2?

1) x is real

2) x is not positive

Ans: C

18. What will be the value of the greatest angle of the triangle ABC?

1) Angles of the triangle are in the ration 2:5:3

2) The side opposite to the greatest angle is the longest side.

Ans: A

19. What is the range of values of x?

1)( x-2 ) / ( 2x + 5 ) < 1/3

2)2x /3 + 17/3 > 3x - 20

Ans: D

20. Of the two which one is the greater -- -3/x , -3/y?

1)      x,y>0 <![endif]>

 Technical Questions

21. Find the output for the following C program

main(){char *p1="Name";char *p2;p2=(char *)malloc(20);while(*p2++=*p1++);printf("%s\n",p2);}Ans. An empty string

Page 98: c,c++

22. Find the output for the following C program

main()

{

int x=20,y=35;

x = y++ + x++;

y = ++y + ++x;

printf("%d %d\n",x,y);

}

Ans. 57 94

23. Find the output for the following C program

main()

{

int x=5;

printf("%d %d %d\n",x,x<<2,x>>2);

}

Ans. 5 20 1

24. Find the output for the following C program

#define swap1(a,b) a=a+b;b=a-b;a=a-b;

main()

{

int x=5,y=10;

swap1(x,y);

printf("%d %d\n",x,y);

swap2(x,y);

printf("%d %d\n",x,y);

}

int swap2(int a,int b)

{

int temp;

temp=a;

b=a;

a=temp;

return;

}

Ans. 10 5

25. Find the output for the following C program

main()

{

char *ptr = "Ramco Systems";

(*ptr)++;

printf("%s\n",ptr);

ptr++;

printf("%s\n",ptr);

Page 99: c,c++

}

Ans. Samco Systems

26. Find the output for the following C program

#include<stdio.h>

main()

{

char s1[]="Ramco";

char s2[]="Systems";

s1=s2;

printf("%s",s1);

}

Ans. Compilation error giving it cannot be an modifiable 'lvalue'

27. Find the output for the following C program

#include<stdio.h>

main()

{

char *p1;

char *p2;

p1=(char *) malloc(25);

p2=(char *) malloc(25);

strcpy(p1,"Ramco");

strcpy(p2,"Systems");

strcat(p1,p2);

printf("%s",p1);

}

Ans. RamcoSystems

28. Find the output for the following C program given that

[1]. The following variable is available in file1.c

static int average_float;

Ans. All the functions in the file1.c can access the variable

29. Find the output for the following C program

# define TRUE 0some codewhile(TRUE){some code }

Ans. This won't go into the loop as TRUE is defined as 0

30. Find the output for the following C program

main()

{

Page 100: c,c++

int x=10;

x++;

change_value(x);

x++;

Modify_value();

printf("First output: %d\n",x);

}

x++;

change_value(x);

printf("Second Output : %d\n",x);

Modify_value(x);

printf("Third Output : %d\n",x);

}

Modify_value()

{

return (x+=10);

}

change_value()

{

return(x+=1);

}

Ans. 12 1 1

31. Find the output for the following C program

main(){int x=10,y=15;x=x++;y=++y;printf("%d %d\n",x,y);}Ans. 11 16

32. Find the output for the following C programmain()

{

int a=0;

if(a=0) printf("Ramco Systems\n");

printf("Ramco Systems\n");

}

Ans. Ony one time "Ramco Systems" will be printed

33. Find the output for the following C program

#include<stdio.h>

int SumElement(int *,int);

void main(void)

{

int x[10];

int i=10;

Page 101: c,c++

for(;i;)

{

i--;

*(x+i)=i;

}

printf("%d",SumElement(x,10));

}

int SumElement(int array[],int size)

{

int i=0;

float sum=0;

for(;i<size;i++)

sum+=array[i];

return sum;

}

34. Find the output for the following C program

#include<stdio.h>

void main(void);

int printf(const char*,...);

void main(void)

{

int i=100,j=10,k=20;

-- int sum;

float ave;

char myformat[]="ave=%.2f";

sum=i+j+k;

ave=sum/3.0;

printf(myformat,ave);

}

35. Find the output for the following C program

#include<stdio.h>

void main(void);

{

int a[10];

printf("%d",((a+9) + (a+1)));

}

36. Find the output for the following C program

#include<stdio.h>

void main(void)

{

struct s{

int x;

float y;

}s1={25,45.00};

Page 102: c,c++

union u{

int x;

float y;

} u1;

u1=(union u)s1;

printf("%d and %f",u1.x,u1.y);

}

37. Find the output for the following C program

#include<stdio.h>

void main(void)

{

unsigned int c;

unsigned x=0x3;

scanf("%u",&c);

switch(c&x)

{

case 3: printf("Hello!\t");

case 2: printf("Welcome\t");

case 1: printf("To All\t");

default:printf("\n");

}

}

38. Find the output for the following C program

#include<stdio.h>

int fn(void);

void print(int,int(*)());

int i=10;

void main(void)

{

int i=20;

print(i,fn);

}

void print(int i,int (*fn1)())

{

printf("%d\n",(*fn1)());

}

int fn(void)

{

return(i-=5);

}

39. Find the output for the following C program

#include<stdio.h>

void main(void);

{

Page 103: c,c++

char numbers[5][6]={"Zero","One","Two","Three","Four"};

printf("%s is %c",&numbers[4][0],numbers[0][0]);

}

40. Find the output for the following C program

int bags[5]={20,5,20,3,20};

void main(void)

{

int pos=5,*next();

*next()=pos;

printf("%d %d %d",pos,*next(),bags[0]);

}

int *next()

{

int i;

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

if (bags[i]==20)

return(bags+i);

printf("Error!");

exit(0);

}

41. Find the output for the following C program

#include<stdio.h>

void main(void)

{

int y,z;

int x=y=z=10;

int f=x;

float ans=0.0;

f *=x*y;

ans=x/3.0+y/3;

printf("%d %.2f",f,ans);

}

42. Find the output for the following C program

#include<stdio.h>

void main(void);

{

double dbl=20.4530,d=4.5710,dblvar3;

double dbln(void);

dblvar3=dbln();

printf("%.2f\t%.2f\t%.2f\n",dbl,d,dblvar3);

}

double dbln(void)

{

double dblvar3;

Page 104: c,c++

dbl=dblvar3=4.5;

return(dbl+d+dblvar3);

}

43. Find the output for the following C program

#include<stdio.h>

static int i=5;

void main(void)

{

int sum=0;

do

{

sum+=(1/i);

}while(0<i--);

}

44. Find the output for the following C program

#include<stdio.h>

void main(void)

{

int oldvar=25,newvar=-25;

int swap(int,int);

swap(oldvar,newvar);

printf("Numbers are %d\t%d",newvar,oldvar);

}

int swap(int oldval,int newval)

{

int tempval=oldval;

oldval=newval;

newval=tempval;}

45. Find the output for the following C program

#include<stdio.h>

void main(void);

{

int i=100,j=20;

i++=j;

i*=j;

printf("%d\t%d\n",i,j);

}

46. Find the output for the following C program

#include<stdio.h>

void main(void);

int newval(int);

void main(void)

Page 105: c,c++

{

int ia[]={12,24,45,0};

int i;

int sum=0;

for(i=0;ia[i];i++)

{

sum+=newval(ia[i]);

}

printf("Sum= %d",sum);

}

int newval(int x)

{

static int div=1;

return(x/div++);

}

47. Find the output for the following C program

#include<stdio.h>

void main(void);

{

int var1,var2,var3,minmax;

var1=5;

var2=5;

var3=6;

minmax=(var1>var2)?(var1>var3)?var1:var3:(var2>var3)?var2:var3;

printf("%d\n",minmax);

48. Find the output for the following C program

#include<stdio.h>

void main(void);

{

void pa(int *a,int n);

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

pa(arr,5);

}

void pa(int *a,int n)

{

int i;

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

printf("%d\n",*(a++)+i);

}

49. Find the output for the following C program

#include<stdio.h>

void main(void);

void print(void);

{

Page 106: c,c++

print();

}

void f1(void)

{

printf("\nf1():");

}

50. Find the output for the following C program

#include "6.c"

void print(void)

{

extern void f1(void);

f1();

}

static void f1(void)

{

printf("\n static f1().");

}

51. Find the output for the following C program

#include<stdio.h>

void main(void);

static int i=50;

int print(int i);

void main(void)

{

static int i=100;

while(print(i))

{

printf("%d\n",i);

i--;

}

}

int print(int x)

{

static int i=2;

return(i--);

}

52. Find the output for the following C program

#include<stdio.h>

void main(void);

typedef struct Ntype

{

int i;

char c;

long x;

Page 107: c,c++

} NewType;

void main(void)

{

NewType *c;

c=(NewType *)malloc(sizeof(NewType));

c->i=100;

c->c='C';

(*c).x=100L;

printf("(%d,%c,%4Ld)",c->i,c->c,c->x);

}

53. Find the output for the following C program

#include<stdio.h>

void main(void);

const int k=100;

void main(void)

{

int a[100];

int sum=0;

for(k=0;k<100;k++)

*(a+k)=k;

sum+=a[--k];

printf("%d",sum);

}

 

                                 

Test Paper :2 Paper Type     : Technical - C & C++

 Posted By        : adminDSQ PAPER 

Techanical paper

Questions 1 -5 are reference to the followig psedo code{input m,n,zTEST:if ((m+n)/3&gt;5)z=z+1 else z =z-1printf m,n,z{(m-m+1;n=n-3)if (m+n+2)&gt;14 then goto testprint m,n,zend}1. what is the final output of the if the input is 2,14,12 (m,n,z)a)1,8,4 b)1,4,8 c)4,8,1 d)8,4,2ans=C.

Page 108: c,c++

2. what is the final output if the input is 1,18,2? (m,n,z)ans) 5,6,2 i.e ans =c.3. How many times is TEST execute ed if the input is 2,14,1?ans) twice ans=c.

4) How many times the TEST exected if the input is 1,18,2?ans)four times 5) what are the values taken by Z when input being 8,24,1?a)only 5 b)only 6 c)neither 5 or 6 d)both 5 and 6ans)D.

6) the function f(x) is defined as followsif x=0 then f(x) =1if x&gt;0 then if ((x&gt;10)then f(x) =x-10 else f(x) =x+1))if x&lt;0 then if (x**2 &lt;100) then f(x) =f(-x+1) else f(x) =f(-(x+1)) 6) the above of f(2) +f(-3) isans=8.7) the value of f(8)+f(9) isans=208) the value of f(1)+f(2)+f(3).............+f(10) isans=659) the value of f(-10)+f(-9)+f(-8) is a) 33 b)25 c)-27 d)27

11. 1997 haeadecimal is a)7cb b)7cd c)7cf d)7ca ans-c

12. the remainder when 9FA (hexa) is divided by 8 is added to the 12(to base ten) to get x.then x has the binary opertion ans=1110

13. the remainder when 1221 (in hexa) is diveded by 17(decimal) in (hexa)isans=014. The binary number 100010011 will the hexa representationans=113

15. The binary number 10011001 will the octal representationans=463

16 Find the odd man out16 a) Intel b)motorola c)nec d)Ibmans =nec

17. a)BIt b)byte c)nibble d)fieldans= field

18 a)Tree b)Root c)Log d)leafans=log19. a)ROM b)PROM c)EPROM d)EEPROMans=ROM

20. a)MOVE b)DEL c)COPY d)RENans=DEL21. What's the output of the following programmain(){int z=3;printf(&quot;%d %d &quot;,z,main());}

Page 109: c,c++

a)prints a value 3 b)prints junk value c)error message d)infinite loop

22) main() {int i=3,j=5;while (i--,J--){printf(&quot;%d %d&quot;.i,j);}}The loop will be executeda)3 times b)5times c)8times d)infinite times

23) main(){int i=3,j=5If(i--,j--)printf(&quot;%d %d &quot;,i,j);}The output of the program for (i,J)is a)3,5 b)3,4 c)2,4 d)2,5ans=B

24) main(){int i=3printf (&quot;%d %d %d &quot;,++i,i-,i+=5);}The the out put of the program isa)8,8,8 b)4,3,8 c)3,2,7 d)4,4,9ans=B

25) main(){int times =5;int i=3;int j=4;int k=34;i=j+k;while(times --){i=timesj=timesk=times}printf(&quot;%d %d %d &quot; ,i,j,k)}THe output of the praogram is (i,j,k)a)19,9,35 b)38,42,80 c)43,47,85 d)15,14,41 ans=C26) main(){int num =32765;while (num++);printf(&quot; %d &quot;,num)}what&quot;s the out put ofthe programa)prints all the number above 32765 including the number 32765b)prints all the number above 32765 excluding the number 32765ans=B.

Page 110: c,c++

27) main(){float k=3.4156printf(&quot;%f %f &quot;,float(k),c(k))}The output of the program a) 3.4156 ,3.4156 b)4,5 c)3,4 d)3.45 3.40ans=C.

28) main(){int bounce =4;printf (&quot;total number of bounce =%d&quot;,bounce ++);}The out put of the program isans=D (stoP)

29) main(){int number =25;char name ='A'printf(&quot;The addition of the name and the number is %o &quot;name +_number)}the output of the program is a)compiler errorb)run time errorans= A

30)

31) ODBC meansans= open data base connectivity32) ASCII stands forans= american standard for information interchange 33) 34) flops stands for ans)floating point operation per second35) by superconductivityans)36) PERT stands forProgram evalution and review techniq37) IMS is aans) data base system38) HTML is aans) Hyper text markup language 39) The default backend of visual basic isans)sybase40) Client server is based on ans) distribution processing

44) computer viruses can spread from one system to anther by means ofa) infected disks b)links to a networkc)downloaded program from a bulletin boardd)all of the programans)D45) A front end processor is usually used inans=multi processing.46) A radio active material of mass 16gms loses in 10 years due toradiation.How many more years will take for the material to attain amass of of 1gm ?

Page 111: c,c++

ans=80 years47) A block of ice floats on water in a beaker as the melts the waterlevel n the beaker will remain the sameans=Remains same.48) if va,vn,vs are velocities of sound in a air ,water ,and steel thenans)vs&gt;vn&gt;va49) in usual computer arthimetic the value of the integer expression22/5*2+8*2/6ans= 8.50) an operting system is aa)file manager b)memory managerc)i/o manager d)all of the aboveans=D.

1.How many liters of water must be added to 30 liters of alcohol to make asolution thatis 25%ans:1202.How much is 3/7 larger than 20 percent of 2ans;1/353.xyz=120,then which of the following cannot be a value of yans:04.a number of subsets of a set s is 128, then s hasans:75. xsqrt(0.09)=3 , then x equalsans:6.perimeter of rectangle is s and the other sideis x, then the other sideans:(s-2x)/2 7.solution of system of equations y-z=0,x+8y=4,3x+4y=7z isans:x=1,y=1,z=1

15. f(x,y) =x**2 -y**2 then the value of f(4,(f(1,2) isans =7.16. if the radius of the circle is incresed by 6% then its area incresedby ans=36%17. the average of seven numbers is 2.5 then their productasn=17.518. the minimum of (2x+1)**2 + (x+2) is at x =ans = (-4/5)19. the probability of getting at least in a single through of threecoins isans=7/8.20. atrain covers the distance D beteween two cities in hhours arriving2 hours late.what rate would permit to train to arrive on schdule? ans= (D/H-2)21. in a single throw of dice ,the chance of throwing a total of 3 isans) 1/216.22. a triangle of sides 3,4,5 then its----isans:623. Which of the following is next smaller invalue than--- one halfans:2/524. if f(x)=1/x then f(f(f(x))) equalsans:1/x25. if f(x)=1/x**2 , then f(f(f(x)))ans:1/x26.if 8x+4y=6 and 4x+5y=7, x+y equl\als ans:1

Page 112: c,c++

27. find the next number in the series 1,2,5,10,17,26ans:3728,.sqrt(0.16)+cubic root(0.027) equalsans:0.729.if a,b&gt;0 and a+b=2 then the max value of ab is ans:1

30. p and q are positiveintegers with their average 5, find how manydifferent values can p takeans:931. if 0&lt;x&lt;1 which of the following is the largestans:1/x33. If x,y,z are three consecutive natural numbers, which of the followingnumbers should be x+y+z ans:2/334. two persons run a race of 100m. the winner won by (110/11)m and onesecond in time. find the speed of lsoer in metans:9.0935. in a group of 15,7 can speak spanish, 8 can speak french and 3 canspeak neither,. how much of the group can speak both french and spanishans:1/536. which of the following intefgers is the square of an integer for every integerans:a**2+2n+137. which of the following has the largest numberical valueans:0.2/0.00000138. ifn is odd which of the following statements is trueans: 3n+1 is even39. which of the following is the primeans:80