iNautix Placement Papers 2011:

Give the Output of the following programs:


1. #define AND &&
#define OR ||
#define LE <=
#define GE >=
main( )
{
char ch = ‘D’;
if((ch GE 65 AND ch LE 90) OR (ch GE 97 AND ch LE 122))
printf(“Alphabet”);
else
printf(“Not an alphabet”);
}
a) No Alphabet
b) Alphabet
c) error
d)None

2. main( )
{
int n[25];
n[0] = 100;
n[24] = 200;
printf(“%d %d”, *n, *(n + 24) + *(n + 0));
}
a) 200 100
b) 100 300
c) 100 200
d) None

3. main( )
{
int arr[ ] = { 0, 1, 2, 3, 4};
int i, *ptr;
for(ptr = arr + 4; ptr = arr; ptr--)
printf(“%d”, *ptr);
}
a) 0 1 2 3 4
b) 4 3 2 1 0
c) 1 2 3 4 0
d)None

4. main( )
{
struct employee
{
char name[25];
int age;
float bs;
};
struct employee e;
e.name = “Hacker”;
e.age = 25;
printf(“%s%d”, e.name, e.age);
}
a) Hacker, 25
b) Error message
c) 25 Hacker d) None

5. #define NULL 0
main( )
{
struct node
{
struct node *previous;
int data;
struct node *next;
} ;
struct node *p, *q;
p = malloc(sizeof(struct node));
q = malloc(sizeof (struct node));
p->data = 75;
q->data = 90;
p->previous = NULL;
p->next = q;
q->previous = p;
q->next = NULL;
while(p!=NULL)
{
printf(“%d\n”, p->data);
p =p->next;
}
}
a) 90 b) 75 c) 90 d) None
75 90 90

6. main( )
{
int i=3;
i=i++;
printf(“%d”,i));
}
a. 3
b. 4
c. undefined
d. Error

7 . What error would the following function give on compilation.
f (int a, int b)
{
int a;
a=20;
return a;
}
a. Missing parentheses in return statement.
b. The function should be defined as int f(int a, int b)
c. Redeclaration of a.
d. None of the above.

8. . #define sqr(x) (x*x)
main( )
{
int a,b=3;
a=sqr(b+2);
printf(“%d”,a);
}
a. 25
b. 11
c. Error
d. Garbage value

9. #define str(x) #x
#define Xstr(x) str(x)
#define oper multiply
main( )
{
char *opername=Xstr(oper);
printf(“%s”,opername);
}
a. oper
b. multiply
c. Error
d. None


10. main( )
{
printf(“%c”,”abcdefgh”[4]);
}
a. a
b. e
c. Error
d. None


11. main( )
{
printf(“%d %d %d”,sizeof(‘3’),sizeof(“3”),sizeof(3));
}
a. 1 1 1
b. 2 2 2
c. 1 2 2
d. 1 1 1


12. main( )
{
struct emp{
char n[20];
int age;}
struct emp e1={“david”,23};
struct emp e2=e1;
if(e1= = e2) printf(“structures are equal”);
}
a. structures are equal
b. No output
c. Error
d. None


13. main( )
{
char a[ ];
a[0] = ‘A’;
printf(“%c”, a[0]);
}
a) Compilation Error
b) No output
c) A
d) None




14. main( )
{
int x = 5;
printf(“%d %d”, x++, ++x);
return 0;
}
a) Error
b) 6, 6
c) 5, 7
d) 7, 6


15. main( )
{
int z = 4;
printf( “%d”, printf(“ %d %d “, z, z));
}
a) 4 4 3
b) 4 4 5
c) 4 4 4
d) Error


16. int i = 0;
main( )
{
printf(“i = %d”, i);
i++;
val( );
printf(“After i=%d”, i);
val( );
}
val( )
{
i =100;
printf(“val’s i=%d\n”, i);
i++;
}
a) i =0
b) i=0
c) Error
d) None of the above


17. main( )
{
int a[ ] = { 10, 20, 30, 40, 50};
int j;
for (j = 0; j < 5; j++)
{
printf(“ \n %d”, * a);
a ++;
}
}
a) 0..5
b) 0..4
c) Error
d) None of the above


18. main( )
{
int a[5] = {2, 4, 6, 8, 10);
int i, b =5;
for(i=0; i<5; i++)
{
f(a[i], &b);
printf(“\n %d %d”, a[i], b);
}
}
f(int x, int *y)
{
x = *(y) +=2;
}
a) 2 7 b) 4 9 c) 7 2 d) Error
4 9 6 11 9 4
6 11 8 13 11 6
8 13 10 15 13 8
10 15 12 17 15 10


19. main ( )
{
int n=20, i = 0;
while(n- - >0);
i = i +n;
}
The end value of i is
(a)210
(b) 20
( c) -1
(d) 200


20. main( )
{
int i = 0; char ch = ‘A’
do {
printf(“%c”, ch);
} while (i++ <5| | ++ch < =’F’);
}
The output of above program is
(a) ABCDEF
(b) AAAAAA BCDEF
(c) A will be displayed infinitely
(d) None of the above


21. Assume that a, b, c are integer variables. Values of a, b and c are 2, 3 and 1 respectively. Which of the following statement is correct regarding the assignment d = a < b < c - 1;
(a) Above statement is syntactically not correct
(b) Value zero will be stored in variable d
(c) Value one will be stored in variable d
(d) Value -1 will be stored in variable d


22. int count, sum;
main( )
{
for(count = 4; sum + = - - count);
printf(“%d”, sum);
}
(a) Program goes into an infinite loop
(b) 356653 will be displayed
(c) 354453 will be displayed
(d) None of the above


23. What will be the result of executing following program
main( )
{
char *x="New";
char *y="Dictionary";
char *t;
void swap (char * , char *);
swap (x,y);
printf("(%s, %s)",x,y);
char *t;
t=x;
x=y;
y=t;
printf("-(%s, %s)",x,y);
}
void swap (char *x,char *y)
{
char *t;
y=x;
x=y;
y=t;
}
a). (New,Dictionary)-(New,Dictionary)
b). (Dictionary, New)-(New, Dictionary
c). (New, Dictionary)-(Dictionary, New)
d). (Dictionary,New)-(Dictionary,New)

24. main( )
{
static float a[ ] = { 13.24, 1.5}
float *j, *k;
j = a;
k = a + 2;
j = j * 2;
k = k/2;
printf(“%f%f ”, *j, *k);
}
a) Error b) Some value c) No output d) None of the above


25. main( )
{
static char s[ ] = “Rendezvous”;
printf(“%d”, *(s+ strlen(s)));
}
a) 0 b) Rendezvous c) ‘0’ d) Error