Csc Placement Paper

Only available on StudyMode
  • Topic: Following
  • Pages : 27 (3975 words )
  • Download(s) : 480
  • Published : February 19, 2012
Open Document
Text Preview
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

9. According to ANSI specifications which is the correct way of declaring main() when it receives command line arguments?

a) main(int argc, char *argv[]) b) main(argc,argv) int argc; char *argv[]; c) main() {int argc; char *argv[]; } d) None of the above

10. What error would the following function give on compilation?

f(int a, int b)
{
int a;
a=20;
return a;
}
a) missing parenthesis in the return statement b) The function should be declared as int f(int a, int b) c) redeclaration of a d) None of the above

11.  If the program (myprog) is run from the command line as myprog 1 2 3 , What would be the output?

main(int argc, char *argv[])
{
int i;
for(i=0;i<argc;i++)
printf("%s",argv[i]);
}
a) 1 2 3 b) C:\MYPROG.EXE 1 2 3
c) MYP d) None of the above

12. If the following program (myprog) is run from the command line as myprog 1 2 3, What would be the output?

main(int argc, char *argv[])
{
int i,j=0;
for(i=0;i<argc;i++)
j=j+ atoi(argv[i]);
printf("%d",j);
}
a) 1 2 3 b) 6 c) error d) "123"

13. If the following program (myprog) is run from the command line as myprog monday tuesday wednesday thursday? What would be the output?

main(int argc, char *argv[])
{
while(--argc >0)
printf("%s",*++argv);
}
a) myprog monday tuesday wednesday thursday b) monday tuesday wednesday thursday c) myprog tuesday thursday d) None of the above

14. In the following code, is p2 an integer or an integer pointer?

typedef int* ptr
ptr p1,p2;
Ans. Integer pointer

15. If the following program (myprog) is run from the command line as myprog friday tuesday sunday, What would be the output?

main(int argc, char *argv[])
{
while(sizeofargv)
printf("%s",argv[--sizeofargv]);
}
a) myprog friday tuesday sunday b) myprog friday tuesday
c) sunday tuesday friday myprog d) sunday tuesday friday

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

main()
{
int i=4;
switch(i)
{
default:
printf("\n A mouse is an elephant built by the Japanese");
case 1:
printf(" Breeding rabbits is a hair raising experience");
break;
case 2:
printf("\n Friction is a drag");
break;
case 3:
printf("\n If practice make perfect, then nobody's perfect"); }
}
a) A mouse is an elephant built by the Japanese b) Breeding rabbits is a hare raising experience c) All of the above d) None of the above...
tracking img