eg: IT, BANK, MECHANICAL, etc..

HCL Solved placement Papers - C questions - part 1

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...

1) main()
{
static char names[5][20]={"pascal","ada","cobol","fortran","perl"};
int i;
char *t;
t=names[3];
names[3]=names[4];
names[4]=t;
for (i=0;i<=4;i++)
printf("%s",names[i]);
}

Answer:

Compiler error: Lvalue required in function main
Explanation:
Array names are pointer constants. So it cannot be modified.

2)  main( )
{
void *vp;
char ch = ‘g’, *cp = “goofy”;
int j = 20;
vp = &ch;
printf(“%c”, *(char *)vp);
vp = &j;
printf(“%d”,*(int *)vp);
vp = cp;
printf(“%s”,(char *)vp + 3);
}

Answer:
g20fy
Explanation:
Since a void pointer is used it can be type casted to any other type pointer. vp = &ch stores address of char ch and the next statement
prints the value stored in vp after type casting it to the proper data type pointer. the output is ‘g’. Similarly the output from second printf is ‘20’. The third printf
statemen t type casts it to print the string from the4th value hence the output is ‘fy’.

3) main()
{
 main();
 }

Answer:

Runtime error : Stack overflow.

Explanation:
main function calls itself again and again. Each time the function is called its return address is stored in the call stack. Since there is no  condition to terminate the function call, the call stack overflows at runtime. So it  terminates the program and results in an error.

4) main()
{
show();
}
void show()
{
printf("I'm the greatest") ;
}

Answer:

Compier error: Type mismatch in redeclaration of show.
Explanation:
When the compiler sees the function show it doesn't know anything
about it. So the default return type (ie, int) is assumed. But when
compiler sees the actual definition of show mismatch occurs since it is
declared as void. Hence the error.
The solutions are as follows:
1. declare void show() in main() .
2.define show() before main().
3.declare extern void show() before the use of show()

Dear CV Reader, Are You Preparing Seriously For Your Placement Tests ?

Click Here To Know What Placement Success Book (Hard Copy) Contains & Know How To Order This Book



Jobs, Placement Papers

Welcome to Placement papers and jobs help portal. Here you can find previous placement questions, sample placement papers, job interview questions and other material pertaining to top Indian companies like Infosys, Wipro, HCL, Satyam, TCS, HCL, HP, Accenture etc.
We are constantly striving to provide you the latest job openings and placement papers and services available from India.

  • Fresher IT Jobs
  • Bank & Finance Jobs
  • Experienced IT Jobs
  • Mechanical Jobs


Footer Links