You are on page 1of 13

1) main()

{
int a=3, b = 5;
printf(&a["Ya!Hello! how is this? %s\n"], &b["junk/super"]);
printf(&a["WHAT%c%c%c %c%c %c !\n"], 1["this"],
2["beauty"],0["tool"],0["is"],3["sensitive"],4["CCCCCC"]);
}

a)Hello! this is junk b)Hello! how is this? super


That is C! That is beaut!

c)Hello! how is this? Junk d)Hello! how is this? super


That is sensitive! That is C!

2) #include<stdio.h>

int main()
{
int i=0;
printf("%d ",sizeof(++i));
printf("%d ",sizeof(++i));
printf("i=%d\n",i);
return 1;
}

a)4 4 i=0 b)2 2 i=2 c)4 4 i=2 d)4 2 i=2

3)#include<stdio.h>
int main()
{
unsigned int x=-1;
int y;
y = ~0;
if(x == y)
printf("same");
else
printf("not same");
return 1;
}

a) same
b) not same
c) warning & same
d) warning & notsame

4) int main()
{
short volatile i=0;
scanf("%ol",&i);
printf("\n%ld\n",i);
return 0;
}
what is the output if input is 258?
a) 258 b) 25 c) 21 d) none
of these

5) #define f(x) (x)*(x)


main()
{
int x=5;
printf("%d",f(f(x++)));
}

a) 900 b)f is not defined for constant values so error


c) 1680 d)625

6) typedef enum errorType{warning, error, exception,}error;

main()
{
error g1;
g1=1;
printf("%d",g1);
}

a) 1

b) Error in g1=1;

c) Error in first statement due to , after exception

d) Error in first statement due to redeclaration of error

7) main()
{
char p[]="String";
int x=0;
if(p=="String")
{
printf("pass 1");
if(p[sizeof(p)-2]=='g')
printf("pass 2");
else
printf("fail 2");
}
else
{
printf("fail 1");
if(p[sizeof(p)-2]=='g')
printf("pass 2");
else
printf("fail 2");
}
}

a) pass 1 pass 2 b) pass 1 fail 2 c) fail 1 pass2 d) fail 1 fail 2

8) #include<string.h>
main()
{
char strp[] = "Never ever say no";
char *chp, c='e';
int i,j;
chp = strrchr(strp, c);
i = chp-strp;
for(j=0;j<=i;j++)
printf("%c",strp[j]);
}

a) Never eve

b) Never say

c) Never ever say n

d) error

9) #include<stdio.h>

int main()
{
int a[0]={0,1,2,3};
a[-1]=2;
printf("%d %d %d %d%d�,
sizeof(a),a[1]d",sizeof(a),a[1],sizeof(a[2]),a[3],a[1]);
return 0;
}

a) 0 garbage 4 3 0
b) 16 2 4 3 0
c) 0 2 4 garbage garbage
d) error

10) #include<stdio.h>
static struct s{
unsigned a:5;
unsigned b:5;
unsigned c:5;
unsigned d:5;
}v={1,2,3,4};

main()
{
printf("size of v = %d",sizeof(v));
}
a)size of v = 2 b)size of v = 4

c)size of v = 8 d)size of v = 6

11) main()
{
int p;
for(p = 1; p<=10 , --p; p=p+2)
puts("Hello");
}

a)Hello(5 times) b)Hello(10 times)

c)no error and no output d)error

12) main()
{
char arr[50];
scanf("%[^\n]",arr);
printf("%10.5s",arr);
printf("\n%-10.5s",arr);
printf("%10.-5s",arr);
}

what is the output if input is "This question is not easy!!" ?

a)This b) This
ThisThis This %10.-5s

c) This d) This
This %10.05a This This10.-5s

13) main()
{
int i;
scanf("%*s%n",&i);
printf("%d",i);
}

what shall be the input so that we get 7 as output?

a)7070707 b)Version 2003


c)welcome d)all the three inputs

14) main()
{
printf("MCA");
printf("\a\b\c\\0CD");
printf("\n\0NITT");
printf("WEL\rCOME");
}
a) MCA\a\b\c\0CD b)MCc\0CD
NITTWEL WEL
COME

c)MCc\0CD d)none of the above


COME
COME

15) main()
{
int a[5]={1,3,6};
int *b;
b=&a[4];
printf("%d %d",a[4],b[-2]);
}

a) garbage value 6 b)negative subscript not allowed

c) 0 6 d) none of the above

16) struct a{
float a;
char b;
struct a *anext;
};
struct b{
int c;
double d;
struct a *e;
struct b *bnext;
}*head;

main()
{
head=(struct b*)malloc(sizeof(struct b));
printf("%d",sizeof(*head));
head->e=(struct a*)malloc(sizeof(struct a));
printf("\n%d",sizeof(*head));
head->bnext=(struct b*)malloc(sizeof(struct b));
printf("\n%d",sizeof(*head));
head->bnext->e=(struct a*)malloc(sizeof(struct a));
printf("\n%d",sizeof(*head));
}

the output will be a:

a) G.P

b) A.P

c) constant

d) error

17) #include <stdio.h>


int main()
{
int a=6,b=8;
a=a&~b|b&~a,b=a&~b|b&~a,a=a&~b|b&~a;
printf(" %d %d",a,b);
return 0;
}

a)6 8 b)8 6 c)0 0 d)1 1

18) #include <stdio.h>

main()
{
enum tag{abc=1,bcd=4,efg,xyz=-7};
printf("%d %d %d",efg,sizeof(bcd),sizeof(enum tag));
}

a) 5 4 16 b) 5 4 4 c) 5 2 8 d) 5 4 2

19) #include <stdio.h>


main()
{
int x,y;
x=ret1();
y=ret2();
printf("%d%d",x,y);
}
ret1()
{
return 1,2;
}
ret2()
{
return (1,2);
}

a)11

b)12

c)21

d)22

20) union con{


struct point{
int x;
int y;
}s;
}u;

int main()
{
u.s.x=12;
printf("%d%d",u.s.x,u.s.y);
}
a)12 12

b)12 garbage

c)12 0

d)none of these

21) #include<stdio.h>

int main()
{
char str[0]="wow";
wow(4,4.5,'e',str);
return 0;
}

wow()
{
printf("Wow!!! What a Function");
}

a)Wow!!! What a Function.

b)error type mismatch in function calling.

c)error because like this only one argument can be passed.

d)error because like this we can pass only integers.

22)main(void)
{
int i=8;
printf("Well done.\n%n",&i);
printf("%s %d","All the best",i);
}

a)Well done.
All the best

b)Well done.
All the best 8

c)Well done.
All the best 11
d)Well done.
-1073752156All the best 8

23)#include <iostream>
using namespace std;

class moo
{
public:
moo()
{
cout<<\"moo::moo()\\n\";
}
moo(int i)
{
cout<<\"moo::moo(int)\\n\";
}
~moo()
{
cout<<\"moo::~moo()\\n\";
}
};

void main()
{
moo m;
m = 10;
}

a) moo::moo()
moo::moo(int)
moo::~moo()
moo::~moo()

b) moo::moo()
moo::~moo()
moo::~moo()

c) moo::moo()
moo::moo(int)
moo::~moo()

d) moo::moo()
moo::~moo()

24)#include <iostream>
using namespace std;

class integer
{
int i;
}
main()
{
cout<<"Version ";
cout<<"2003";
}

a)Version 2003

b)Version 2003 with warning

c)Version

d)Error

25) #include <iostream>


using namespace std;

class integer
{
int i;
public:
integer(int a)
{
i=a;
}
void get_int()
{
cout<<"Enter an integer : ";
cin>>i;
}

void put_int()
{
cout<<i;
}
void operator ++()
{
i++;
}
};

int main()
{
integer i;
i.get_int();
i++;
i.put_int();
return 0;
}

if 100 is the input what will be the out put:

a)100

b)101

c)100 with warning

d)error

26)#include <iostream>
using namespace std;

class integer
{
int i;
public:
integer()
{
i=0;
}
int &add(int a)
{
int &sum=i;
i+=a;
return &sum;
}

};

int main()
{
integer a1;
int &result=a1.add(10);
cout<<result;
return 0;
}

a)10

b)20

c)garbage

d)error

27) include <iostream>


using namespace std;

class base1
{
public :
void fun()
{
cout<<"base1";
}

};

class base2
{
public:
void fun()
{
cout<<"base2";
}
};

class derieved:public base1,public base2


{
public:
void display()
{
cout<<"Derieved class";
}
};

int main()
{
derieved d;
d.fun();
}

a)base1

b)base2

c)base1base2

d) Error

28) #include <iostream>


using namespace std;

class index
{
private:
int count;
public:
index()
{
count = 0;
}

int operator ++()


{
return ++count;
}
};

int main()
{
class index b;
cout<<b++;
cout<<++b;
}

a)0 1

b)0 2

c)1 2

d)error

29)
#include<iostream>
using namespace std;

void display(char *);


void display(const char *);

int main()
{
char *ch1="Hello";
const char *ch2="Bye";
display(ch1);
display(ch2);
return 0;

void display(char *p)


{
cout<<1<<p;
}

void display(const char *p)


{
cout<<2<<p;
}

a)1Hello1Bye

b)1Hello2Bye

c)2Hello2Bye

d)Error

30) #include <iostream>


using namespace std;

class integer
{
public:
int i;
int &fun()
{
i=2;
return i;
}
};

int main()
{
integer a;
a.fun()=2003;
cout<<a.i;
}

a)2003

b)2

c)error

d)none of these

You might also like