Home »» Placement Papers »» All Papers »» L & T Infotech, »» Placement Paper

LnT Infotech Placement Paper : 45568 (Technical-C)


LnT  Aptitude Questions with Answers

1) What can be said of the following?

struct Node {
char *word;
int count;
struct Node left;
struct Node right;
}

a) Incorrect definition
b) Structures cannot refer to other structure
c) Structures can refer to themselves. Hence the statement is OK
d) Structures can refer to maximum of one other structure

Answer :c

2) What is the output of the following program?

main()
{
int a=10;
int b=6;

if(a=3)
b++;
printf("%d %dn",a,b++);
}

a) 10, 6

b) 10, 7

c) 3, 6

d) 3, 7

e) none

Answer: d

3) What can be said of the following program? 

main ()
{
enum Months {JAN =1,FEB,MAR,APR};
Months X = JAN;
if(X==1)
{
printf("Jan is the first month");
}
}

a) Does not print anything
b) Prints: Jan is the first month
c) Generates compilation error
d) Results in runtime error

Answer: b 

4) What is the output of the following program? 


int x= 0x65;
main()
{
char x;
printf("%dn",x);
}

a) Compilation error 
b) 'A' 
c) 65 
d) Unidentified

Answer: a

5) What is the output of the following program?

main()
{
int l=6;
switch(l)
{ default : l+=2;
case 4: l=4;
case 5: l++;
break;
}
printf("%d",l);
}

a) 8

b) 6

c) 5

d) 4

e) none

Answer: c

6) What is the output of the following program? (has been used to indicate a space)

main()
{
char s[]="Hello,.world";
printf(%15.10s",s);
}

a) Hello, World...
b)....Hello,. or
c) Hello,. or....
d) None of the above 

Answer: d

7) What is the output of the following program?

main()
{
int x=20;
int y=10;
swap(x,y);
printf("%d %d",y,x+2);
}
swap(int x,int y)
{
int temp;
temp =x;
x=y;
y=temp;
}

a)10, 20

b) 20, 12

c) 22, 10

d)10, 22

e)none

Answer: d

8) What is the output of the following problem?


#define INC(X) X++
main()
{
int X=4;
printf("%d",INC(X++));
}


a) 4

b) 5

c) 6

d) compilation error

e) runtime error


Answer: d

9). What is the output of the following program?

main()
{
char *src = "Hello World";
char dst[100];
strcpy(src, dst);
printf("%s",dst);
}
strcpy(char *dst,char *src)
{
while(*src) *dst++ = *src++;
}

a) "Hello World" 
b)"Hello" 
c)"World" 
d) NULL 
e) unidentified

Answer: d

10) What is the size of the following union?

Assume that the size of int =2, size of float =4 and size of char =1.
Union Tag{
int a;
flaot b;
char c;
};

a) 2

b) 4

c) 1

d) 7

Answer: b

Predict the output or error(s) for the following Questions:

11) main()
  {
  static int var = 5;
  printf("%d ",var--);
  if(var)
  main();
  }
a) 5 4 3 2 1

b) 5 3 4 1 2

c) 6 5 4 3 2

d) 4 2 3 6 5


Answer:a

Explanation:When static storage class is given, it is initialized once. The change in the value of a static variable is retained even between the function calls. Main is also treated like any other ordinary function, which can be called recursively. 

12) void main()
{
  int  const * p=5;
  printf("%d",++(*p));
}

a) Integer

b) Constant

c) 5

d) Compiler error


Answer: d
Explanation: Compiler error: Cannot modify a constant value. 
p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".

13) main()
{
  float me = 1.1;
  double you = 1.1;
  if(me==you)
printf("I love U");
else
  printf("I hate U");
}
a) Error

b) I Love U

c) I hate U

d) None of these


Answer: c


Explanation:
For floating point numbers (float, double, long double) the values cannot be predicted exactly. Depending on the number of bytes, the precession with of the value  represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double.
Rule of Thumb: 
Never compare or at-least be cautious when using floating point numbers with relational operators (== , >, <, <=, >=,!= ) . 

14)  main()
{
  char *p;
  printf("%d %d ",sizeof(*p),sizeof(p));
}

a) 1 2

b) 1 3

c) 2 1

d) 3 1


Answer: a

Explanation:
The sizeof() operator gives the number of bytes taken by its operand. P is a character pointer, which needs one byte for storing its value (a character). Hence sizeof(*p) gives a value of 1. Since it needs two bytes to store the address of the character pointer sizeof(p) gives 2.

15) main()
{
  printf("%x",-1<<4);
}

a) ff

b) fff

c) fff0

d) 4

e) None of these


Answer: c

Explanation :
-1 is internally represented as all 1's. When left shifted four times the least significant 4 bits are filled with 0's.The %x format specifier specifies that the integer value be printed as a hexadecimal value.

16)  main()
{
  int i=3;
  switch(i)
   {
  default:printf("zero");
  case 1: printf("one");
  break;
  case 2:printf("two");
  break;
  case 3: printf("three");
  break;
  } 
}

a) 1

b) 2

c) 3

d) 4
Answer : c

Explanation :The default case can be placed anywhere inside the loop. It is executed only when all other cases doesn't match.

17)   #define int char
main()
{
  int i=65;
  printf("sizeof(i)=%d",sizeof(i));
}

a) sizeof(i)=1

b) sizeof(i)=2

c) sizeof(i)=3

d) sizeof(i)=4

Answer: 1

Explanation: Since the #define replaces the string  int by the macro char

18) main()
{
int i=10;
i=!i>14;
Printf ("i=%d",i);
}

a) i=1

b) i=4

c) i=5

d) i=0


Answer: d

Explanation:In the expression !i>14 , NOT (!) operator has more precedence than ‘ >’ symbol.  ! is a unary logical operator. !i (!10) is 0 (not of true is false).  0>14 is false (zero).


Comment

0 Answers