Instructions:
1. Please ignore any case-sensitive errors and un-included libraries.
1. Please ignore any case-sensitive errors and un-included libraries.
2. Time duration : 30
min.
Q1.
main( )
{
int i;
clrscr();
printf("%d", &i)+1;
scanf("%d", i)-1;
}
a. Runtime error. b. Runtime error. Access violation.
c. Compile error. Illegal syntax d. None of the above
Q2.
#define POWER(A) A * A * A
Q1.
main( )
{
int i;
clrscr();
printf("%d", &i)+1;
scanf("%d", i)-1;
}
a. Runtime error. b. Runtime error. Access violation.
c. Compile error. Illegal syntax d. None of the above
Q2.
#define POWER(A) A * A * A
main( )
{
printf("%d", 245/POWER(10+5));
}
a. error b. 2 c. 19 d. none of the above
{
printf("%d", 245/POWER(10+5));
}
a. error b. 2 c. 19 d. none of the above
Q3.
union u
{
struct st
{
int i = 4;
int j = 4;
int k = 4;
int l;
}st;
int i;
}u;
main( )
{
u.i = 100;
printf("%d, %d, %d",u.i, u.st.i, u.st.l);
}
a. 4, 4, 0 b. 0, 0, 0 c. 100, 4, 0 d. 40, 4, 0
Q4.
main( )
{
int i, j, *p;
i = 25;
j = 100;
p = &i; // Address of i is assigned to pointer p
printf("%f", i/(*p) ); // i is divided by pointer p
}
To execute it correctly, what changes can we make in the statement : i/(*p) ?
a. Runtime error. b. 1.00000 c. Compile error d. 0.00000
Q5.
main( )
{
char *p = "hello world";
p[0] = 'H';
printf("%s", p);
}
a. Runtime error. b. Hello world c. Compile error d. hello world
union u
{
struct st
{
int i = 4;
int j = 4;
int k = 4;
int l;
}st;
int i;
}u;
main( )
{
u.i = 100;
printf("%d, %d, %d",u.i, u.st.i, u.st.l);
}
a. 4, 4, 0 b. 0, 0, 0 c. 100, 4, 0 d. 40, 4, 0
Q4.
main( )
{
int i, j, *p;
i = 25;
j = 100;
p = &i; // Address of i is assigned to pointer p
printf("%f", i/(*p) ); // i is divided by pointer p
}
To execute it correctly, what changes can we make in the statement : i/(*p) ?
a. Runtime error. b. 1.00000 c. Compile error d. 0.00000
Q5.
main( )
{
char *p = "hello world";
p[0] = 'H';
printf("%s", p);
}
a. Runtime error. b. Hello world c. Compile error d. hello world
Q6. How will you print % character?
a. printf("%) b. printf("\%) c. printf("%% ) d. printf("\%% )
Q7.
const int perplexed = 2;
#define perplexed 3
main( )
{
#ifdef perplexed
#undef perplexed
#define perplexed 4
#endif
printf("%d",perplexed);
}
a. 0 b. 2 c. 4 d. none of the above
Q8.
struct Foo
{
char *pName;
};
main( )
{
struct Foo *obj = malloc(sizeof(struct Foo));
clrscr();
strcpy(obj->pName,"Your Name");
printf("%s", obj->pName);
}
a. Your Name b. compile error c. Name d. Runtime error
struct Foo
{
char *pName;
};
main( )
{
struct Foo *obj = malloc(sizeof(struct Foo));
clrscr();
strcpy(obj->pName,"Your Name");
printf("%s", obj->pName);
}
a. Your Name b. compile error c. Name d. Runtime error
Q9.
struct Foo
{
char *pName;
char *pAddress;
};
main( )
{
struct Foo *obj = malloc(sizeof(struct Foo));
clrscr();
obj->pName = malloc(100);
obj->pAddress = malloc(100);
strcpy(obj->pName,"Your Name");
strcpy(obj->pAddress, "Your Address");
free(obj);
printf("%s", obj->pName);
printf("%s", obj->pAddress);
}
a. Your Name, Your Address b. Your Address, Your Address
c. Your Name Your Name d. None of the above
Q10.
main( )
{
char *a = "Hello ";
char *b = "World";
clrscr();
printf("%s", strcat(a,b));
}
a. Hello b. Hello World c. HelloWorld d. None of the above
Q11.
main( )
{
char *a = "Hello ";
char *b = "World";
clrscr();
printf("%s", strcpy(a,b));
}
a. Hello b. Hello World c. World d. None of the above
Q12.
main( )
{
printf("%d, %d", sizeof('c'), sizeof(100));
}
a. 2, 2 b. 2, 100 c. 4, 100 d. 4, 4
struct Foo
{
char *pName;
char *pAddress;
};
main( )
{
struct Foo *obj = malloc(sizeof(struct Foo));
clrscr();
obj->pName = malloc(100);
obj->pAddress = malloc(100);
strcpy(obj->pName,"Your Name");
strcpy(obj->pAddress, "Your Address");
free(obj);
printf("%s", obj->pName);
printf("%s", obj->pAddress);
}
a. Your Name, Your Address b. Your Address, Your Address
c. Your Name Your Name d. None of the above
Q10.
main( )
{
char *a = "Hello ";
char *b = "World";
clrscr();
printf("%s", strcat(a,b));
}
a. Hello b. Hello World c. HelloWorld d. None of the above
Q11.
main( )
{
char *a = "Hello ";
char *b = "World";
clrscr();
printf("%s", strcpy(a,b));
}
a. Hello b. Hello World c. World d. None of the above
Q12.
main( )
{
printf("%d, %d", sizeof('c'), sizeof(100));
}
a. 2, 2 b. 2, 100 c. 4, 100 d. 4, 4
Q13.
main( )
{
int i = 100;
clrscr();
printf("%d", sizeof(sizeof(i)));
}
a. 2 b. 100 c. 4 d. none of the above
main( )
{
int i = 100;
clrscr();
printf("%d", sizeof(sizeof(i)));
}
a. 2 b. 100 c. 4 d. none of the above
Q14.
main( )
{
int c = 5;
printf("%d", main||c);
}
a. 1 b. 5 c. 0 d. none of the above
main( )
{
int c = 5;
printf("%d", main||c);
}
a. 1 b. 5 c. 0 d. none of the above
Q15.
main( )
{
int i =10, j = 20;
clrscr();
printf("%d, %d, ", j-- , --i);
printf("%d, %d ", j++ , ++i);
}
a. 20, 10, 20, 10 b. 20, 9, 20, 10 c. 20, 9, 19, 10 d. 19, 9, 20, 10
main( )
{
int i =10, j = 20;
clrscr();
printf("%d, %d, ", j-- , --i);
printf("%d, %d ", j++ , ++i);
}
a. 20, 10, 20, 10 b. 20, 9, 20, 10 c. 20, 9, 19, 10 d. 19, 9, 20, 10
Q16.
main( )
{
int x=5;
for(;x!=0;x--) {
printf("x=%d", x--);
}
}
a. 5, 4, 3, 2,1 b. Lvalue required c. 5, 3, 1 d. Infinite Loop
main( )
{
int x=5;
for(;x!=0;x--) {
printf("x=%d", x--);
}
}
a. 5, 4, 3, 2,1 b. Lvalue required c. 5, 3, 1 d. Infinite Loop
17.
main( )
{
int A=6;
switch(A)
{ default : A+=2;
case 4: A=4;
case 5: A++;
break;
}
printf("\n A = %d",A);
}
a)8 b)6 c)5 d)4
main( )
{
int A=6;
switch(A)
{ default : A+=2;
case 4: A=4;
case 5: A++;
break;
}
printf("\n A = %d",A);
}
a)8 b)6 c)5 d)4
Q18.
#define INC(X) X++
main( )
{
int X=4;
printf("%d",INC(X++));
}
a)4 b)5 c)6 d)compilation error error
main( )
{
int X=4;
printf("%d",INC(X++));
}
a)4 b)5 c)6 d)compilation error error
Q19. What is the output ?
main(
)
{
char i;
clrscr( );
for(i=120;i<=128;i++)
{
printf("%d
",i);
}
getch( );
}
Q20. What is the
output ?
extern int j;
void main( )
{
int i=0;
clrscr( );
for(i=0;i<=2;i+=1) {
j=5;
printf("
%d ",j);
j++; }
getch( ); }
feel free to give me feedback...so that I can add more test papers for u
ReplyDeleteIn question 2 correct answer should be d. None of these, as division will be done first. 245/10+5*10+5*10+5 will become 24+50+50+5 which will be 129.
ReplyDeleteGood Collection of questions post more questions if possible.Cheers
Regards, MohitTare
Thanx Mohit...i didn't execute it
Delete