Thursday, December 25, 2008

Command line Argument Aptitude Question with Answers

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
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
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:
Q7. #define MAN(x,y) (x)>(y)?(x):(y)
{
inti=10;j=5;k=0;
k= MAX(i++,++j)
printf(%d %d %d %d,i,j,k)
}
Ans. 10 5 0
Q3. struct list{
int x;
struct list *next;
}*head;
the struct head.x =100
Is the above assignment to pointer is correct or wrong ?
Ans. Wrong


Q4.What is the output of the following ?
int i;
i=1;
i=i+2*i++;
printf(%d,i);
Ans. 4

Q5. FILE *fp1,*fp2;
fp1=fopen("one","w")
fp2=fopen("one","w")
fputc('A',fp1)
fputc('B',fp2)
fclose(fp1)
fclose(fp2)}
a.error b. c. d.
Ans. no error. But It will over writes on same file.
7. For the following C program
#define AREA(x)(3.14*x*x)
main()
{floatr1=6.25,r2=2.5,a;
a=AREA(r1);
printf("\n Area of the circle is %f", a);
a=AREA(r2);
printf("\n Area of the circle is %f", a);
}
What is the output?
Ans. Area of the circle is 122.656250
Area of the circle is 19.625000
15.
main()
{
static i=3;
printf("%d",i--);
return i>0 ? main():0;
}

Ans: 321
9.
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.

10.
void main()
{
int i=7;
printf("%d",i++*i++);
}

Ans: 56

11.
#define one 0
#ifdef one
printf("one is defined ");
#ifndef one
printf("one is not defined ");

Ans: "one is defined"


12.
void main()
{
intcount=10,*temp,sum=0;
temp=&count;
*temp=20;
temp=∑
*temp=count;
printf("%d %d %d ",count,*temp,sum);
}

Ans: 20 20 20
53. For the following C program
void main()
{
unsigned char c;
for(c=0;c!=256;c=c+2)
printf("%d",c);
getch();
}


(a) 127
(b) 128
(c) 256
(d) infinitely
Ans: (d)
57. For the following program
int i;
i=2;
i++;
if(i==4)
{printf(i=4);
}
else
{printf(i=3);
}
Output of the program ?

a) 4
b) 3
c) unpredictable
d) none

Ans. (b)
58. What is FAT?.

a) File Allocation Table
b) File Access Table
c) FDD Allocation Table
d) None of the above

No comments:

Blog List