Search This Blog

Friday, 6 January 2012

CSC Placement Paper

CSC Placement Paper  2011:-

1. Point out the error in the following program

main()
{
const char *fun();
*fun()='A';
}
const char *fun()
{
return "Hello";
}
Ans. fun() returns to a "const char" pointer which cannot be modified

2. 
What would be the output of the following program?

main()
{
const int x=5;
int *ptrx;
ptrx=&x;
*ptrx=10;
printf("%d",x);
}
a) 5 b) 10 c) Error d) Garbage value

3. A switch statement cannot include

a) constants as arguments b) constant expression as arguments
c) string as an argument d) None of the above

4. How long the following program will run?

main()
{
printf("\nSonata Software");
main();
}
a) infinite loop b) until the stack overflows
c) All of the above d) None of the above

5. On combining the following statements, you will get char*p; p=malloc(100);

a) char *p= malloc(100) b) p= (char*)malloc(100)
c) All of the above d) None of the above

6.Point out the error in the following program

main()
{
int a=10;
void f();
a=f();
printf("\n%d",a);
}
void f()
{
printf("\nHi");
}
Ans. The program is trying to collect the value of a "void" function into an integer variable.

7. In the following program how would you print 50 using p?

main()
{
int a[]={10, 20, 30, 40, 50};
char *p;
p= (char*) a;
}
Ans. printf("\n%d",*((int*)p+4));

8. Would the following program compile?

main()
{
int a=10,*j;
void *k;
j=k=&a;
j++;
k++;
printf("\n%u%u",j,k);
}
a) Yes b) No, the format is incorrect
c) No, the arithmetic operation is not permitted on void pointers
d) No, the arithmetic operation is not permitted on pointers

No comments:

Post a Comment