|
|
|
Debugging – C++ & Java
1. What output is produced by the following program segment?
String name; int i; boolean startWord; name = "Richard M. Nixon"; startWord = true; for (i = 0; i < name.length(); i++) { if (startWord) System.out.print (name.charAt(i)); if (name.charAt(i) == ' ') startWord = true; else startWord = false; }
2. What is the output?
class complex { double re; double im; public: complex (): re (0), im (0) {} complex (double n) {re=n, im=n ;} complex (int m, int n) {re=m, im=n ;} void print () {cout<};
void main () { complex c3; double i=5; c3 = i; c3.print (); }
3. What is the output in the following program? void main () { char c=-64; int i=-32 unsigned int u =-16; if(c>i) { printf("pass1,"); if(cprintf("pass2"); else printf("Fail2"); } else{ printf("Fail1); if(iprintf("pass2"); else printf("Fail2"); } }
4. What will be the result of the following program? char *gxxx( ) { static char xxx[1024]; return xxx; } void main( ) { char *g="string"; strcpy(gxxx(),g); g = gxxx(); strcpy(g,"old string"); printf("The string is : %s",gxxx());
}
5. What is the output?
#include
class fig2d { int dim1; int dim2;
public: fig2d () {dim1=5; dim2=6 ;}
virtual void operator<< (ostream & rhs); };
void fig2d::operator<<(ostream &rhs) { rhs <dim1<<" "<dim2<<" "; }
void main () { fig2d obj1; obj1 << cout; }
Answers 1. R M N 2. 5 5 3. Fail1 Pass2 4. The string is: old string 5. 5 6
|
| Author: Vidya 23 May 2008 | Member Level: Diamond Points : 2 |
useful information
|