You are on page 1of 10

1.

# include <stdio.h>
main()
{
const int i = 100;
int *p = &i;
*p = 200;
printf("%d\n",i);
}

2.
#define prn(a) printf("%d",a)
#define print(a,b,c) prn(a), prn(b), prn(c)
#define max(a,b) (a<b)? b:a
main()
{
int x=1, y=2;
print(max(x++,y),x,y);
print(max(x++,y),x,y);
}

3.
main()
{
char as[] = "\\0\0";
int i = 0;
char ch='a';
do{
switch( as[i++])
{
case '\\' : printf("A");
break;

case 0 : printf("B");
break;

default : printf("C");
break;

}
} while(i<3);

4.*/
main()
{
int i = 10;
printf(" %d %d %d \n", ++i, i++, ++i);
}
/*void main()
{
char input[] = "SSSWILTECH1\1\1";
int i, c;
for ( i=2; (c=input[i])!='\0'; i++){
switch(c){
case 'a': putchar ('i'); continue;
case '1': break;
case 1: while (( c = input[++i]) != '\1' && c!= '\0');
case 9: putchar('S');
case 'E': case 'L': continue;
default: putchar(c);continue;
}
putchar(' ');
}
putchar('\n');
}*/

/*6.
# include <string.h>
main()
{
int i=0;
char *cat = "software\0contest";
while (strlen(*cat++))
{
i++;
printf("%d\n",i);
}
}

7.
main()
{
enum tag{low='a',high='b',med='c'};
char try=low;
printf("\nthe size of the variable=%d",sizeof(tag));
switch(try)
{
case 'a':printf("\nyou must print a");
case 'b':printf("\nyou must print b");
case 'c':printf("\nyou must print c");
}
}

8.
#include <string.h>
main(){
char p[]="MalayalaM";
char t;
int i,j;
for(i=0,j=strlen(p);i<j;i++){
t=p[i];
p[i]=p[j-i];
p[j-i]=t;
}
printf("%s",p)�
}
�9.
main()
{
# define MyDef 1
printf(&MyDef["a%sing"],&(MyDef-1)["Twist"]+'i'-0x69);
}

10.
Fo� a� inpu� o�
REC
VERSION
SWCONT
$
writ� th� output.*/
/*void main()
{
myfunc();
}
myfunc()
{
char a[80];
scanf("%s",a);
if (!strchr(a,'$'))
myfunc();
printf("%s",a);
}

11.*/
/*main()
{
int a,b;
a=0010;
b=0100;
a-=(b=(a+=b)-b);
printf("a=%d b=%d",a,b);
}*/

/*12.
main()
{
struct xyz { int xyz;};
struct xyz xyz;
xyz.xyz=10;
printf("%d",xyz.xyz);
}

The output of the above code is

a. will not compile


b. 10
c. 100
d. none of the above

13.
static int i=5;
void main(void)
�{
int sum=0;
do
{
sum+=(1/i);
}while (0 < i--);
}
14.
# include <alloc.h>
main()
{
char *x="This is a";
char y[]= "sitter";
char *z;
z=(char *)malloc(sizeof(x)+sizeof(y)=1);
strcpy(z,y);
strcat(z,y);
printf("%s+%s=%s",y,x,z);
}

15.
# define scanf "%s version software contest"
main()
{
printf(scanf,scanf);
}

16.
#include <stdio.h>
main()
{
int a=0,b=1;
printf("%d",!(a ^= !( a ~= ( b >> 4 >> 4 << 2 ) ) ) );
}

17.
MAIn()
{
int m=10;
switch(m)
{
case 2+10/2*6-10-2 : printf("how are you");
case 2-10+6*5-2 : printf("i am here");
default:printf("i am not here");
}
}

18.
main()
{
char quote[]="all the best";
char *ptr1 = quote,*ptr2 = quote + sizeof(quote)-1;
int i;
for(i=0;ptr1!=ptr2;i++)
{
--ptr2;
� printf("%c",*ptr1);
printf("%c",*ptr2);
++ptr1;
}
printf("\n%d",i);
}
19.
# define PRINTX printf("%d\n",x)
main()
{
int x=2,y,z;
x*=3+2;PRINTX;
x*=y=z=4;PRINTX;
x=y==z;PRINTX;
x==(y=z);PRINTX;
}

20.
main()
{
char c=65;
switch(c)
{
case 65 : switch(c++)
{
case 65 :putchar('A');
break;
case 66 :putchar('B');
break;
}
case 'B' : putchar('A');
break;
}
}
.pa
�21.
main()
{
int i=1;
clrscr();
switch(i)
{
do
{
case 1:printf("\nhello");
case 0:printf("hai");
}while (i--);
}
}

22.
#include <iostream.h>
class questionclass
{
protected :
int howru;
public :
void askquestion(int value)
{
howru = value;
}
virtual void tellmehowur()=0;
};

class answerclass : public questionclass


{
private :
int iamfine;
public :
answerclass(int value)
{
iamfine = value;
}
void tellmehowur()
{
howru = iamfine;
cout<<"The answer is "<<howru;
}
};
what will be the output of each of the following main()
(i)
main()
{
questionclass qobj1;
qobj1.askquestion(23);
qobj1.tellmehowur();
}
(ii)
main()
{
answerclass aobj(23);
questionclass & qref = aobj;
qref.tellmehowur();
}

23.
#include <iostream.h>
class constclass
{
const int iremainthesame;
public :
constclass(int value)
{
iremainthesame= value;
}
void showvalue()
{
cout<<"The value of the variable is "<<iremainthesame<<endl;
}
};

main()
{
int i = 0;
constclass cobj(i++);
cobj.showvalue();
}
24.
#include <iostream.h>
class pvtdestructor
{
int canidestroythis;
~pvtdestructor()
{
canidestroythis = 0;
cout<<"it works!!"<<endl;
}
public :
pvtdestructor()
{
canidestroythis = 23;
cout<<"in the constructor"<<endl;
}

};

main()
{
pvtdestructor object;
}
.pa
�25.
#include <iostream.h>
class base
{
protected :
void function(double arg)
{
cout<<"The real value is "<<arg<<endl;
}
};
class derived : public base
{
public :
void function(int arg)
{
cout<<"The integer value is "<<arg<<endl;
}
};

what would be the output in each of the following cases :


(i)
main()
{
derived dobject;
float arg = 2.009;
dobject.function(arg);
}

(ii)
main()
{
derived dobj;
base& bref = dobj;
float arg = 2.009;
bref.function(arg);
}

26.
#include <iostream.h>
class operclass
{
int i,j;
public :
operclass()
{
i = 21;
j = 23;
}
void operator ++()
{
i++;
j++;
}
};
main()
{
operclass obj;
obj++;
}
�27.
#include <iostream.h>
main()
{
int integer1 = 23, integer2 = 21;
int &reftointeger;
reftointeger = integer1;
cout<<"the referred integer holds the value of "<<reftointeger<<endl;
reftointeger = integer2;
cout<<"the referred integer now holds the value of "<<reftointeger<<endl;
}

28.
#include <iostream.h>
class shape
{
public :
static float area ;
virtual static void display_area()
{
cout<<"The area of the shape is "<<area;
}
};

class square : public shape


{
private : int side;
public :
square(int s)
{
side = s;
area = s*s ;
}

void display_area()
{
cout<<"The area of the square is "<<area;
}

};

main()
{
square sq(1);
sq.display_area();
}
.pa
�29.
#include <iostream.h>
class storageclass
{
static int si;
const int ci;
public :
storageclass():ci(0)
{
}
void constfun() const
{
ci++;
si++;
show();
}

void show() const


{
cout<<"static int is "<<si<<endl;
cout<<"const int is"<<ci<<endl;
}
};

int storageclass::si=0;
main()
{
storageclass sobj;
sobj.constfun();
}

30.
#include <iostream.h>
class staticlass
{
int data;
public :

staticlass()
{
data = 23;
}

void show()
{
cout<<"the data value is "<<data<<endl;
}

static void showcaller()


{
show();
}
};

main()
{
staticlass sobj;
sobj.showcaller();
}
�*/

You might also like