How Placement Success Book
(Hard Copy) Can Help Your Preparation?
Dear Reader, you can now prepare simultaneously for placement tests of several companies like TCS, Wipro, HCL, Infosys, CTS, Syntel, Mahindra Satyam, L&T Infotech, IBM, 3i Infotech, Accenture & other leading Indian companies...
Click To Know How Placement Success Book (Hard Copy)Can Help You...
Here are some solved questions from HCL Placement Papers
1) #include<stdio.h>
main()
{
struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s=malloc(sizeof(struct xx));
printf("%d",s->x);
printf("%s",s->name);
}
Answer:
Compiler Error
Explanation:
Initialization should not be done for structure members inside the structure declaration
2) main()
{
int *j;
{
int i=10;
j=&i;
}
printf("%d",*j);
}
Answer:
10
Explanation:
The variable i is a block level variable and the visibility is inside that block only. But the lifetime of i is lifetime of the function so it lives upto the exit of main
function. Since the i is still allocated space, *j prints the value stored in i since j points i.
3) int i,j;
for(i=0;i<=10;i++)
{
j+=5;
assert(i<5);
}
Answer:
Runtime error: Abnormal program termination. assert failed (i<5), ,
Explanation:
asserts are used during debugging to make sure that certain conditions are satisfied. If assertion fails, the program will terminate reporting the same. After debugging use,
#undef NDEBUG and this will disable all the assertions from the source code. Assertion is a good debugging tool to make use of..
4) main()
{
int i;
printf("%d",scanf("%d",&i)); // value 10 is given as input here
}
Answer:
1
Explanation:
Scanf returns number of items successfully read and not 1/0. Here 10
is given as input which should have been scanned successfully. So
number of items read is 1.
Click Here To Know What Placement Success Book (Hard Copy) Contains & Know How To Order This Book