ludrr===;s - inplant training tricks...can the following piece of code be executed? char *...

11
I D7 p~ (j) Question Set No. : 107 LUDRr===;S Instructions: 1. All the questions are to be answered and maximum time 60 minutes. 2. This question paper contains 30 C aptitude questions. 3. Each question carries equal mark. 4. No negative marks 5. Maximum mark 30. 6. Please do not write any marks on the question paper. 7. Ask for rough sheets if required. 8. Directions for answering the questions are given in the test question paper before each group of questions to which they apply. Read these directions carefully and answer the questions by darkening the appropriate ovals. 9. Follow the instructions of the invigilator. Candidates found violating the instructions will be disqualified. *'

Upload: dinhdan

Post on 27-Mar-2018

224 views

Category:

Documents


2 download

TRANSCRIPT

I D7 p~(j)

Question Set No. : 107

LUDRr===;S

Instructions:

1. All the questions are to be answered and maximum time 60 minutes.

2. This question paper contains 30 C aptitude questions.

3. Each question carries equal mark.

4. No negative marks

5. Maximum mark 30.

6. Please do not write any marks on the question paper.

7. Ask for rough sheets if required.

8. Directions for answering the questions are given in the test questionpaper before each group of questions to which they apply. Read thesedirections carefully and answer the questions by darkening theappropriate ovals.

9. Follow the instructions of the invigilator. Candidates found violatingthe instructions will be disqualified.

*'

folp~

C0 BRR~DR,"",5

1. What would be the output of the following program.#include<stdio.h>mainO{

extern int a;printf("%d",a);;

}int a=20;

(a) 20 (b) 0

2.Whatwould be the output of the following program.mainO{

int a[5]={2,3};printf("\n %d %d %d",a[2],a[3],a[4]);

}

(a) garbage value (b) 2 3 3

3.What would be the output of the following program.mainO{

int i=-3,j=2,k=0,m;m=++i&&++jU++k;printf("\n %d %d %d %d",i,j,k,m);

}

(a) -2 3 0 1 (b) -3 2 0 1

4.Whatwould be the output of the following program.mainO{

int a,b;a=sumdig(123);b=sumdig(123);printf("%d %d",a,b);

}sumdig(intn){

static int s=O;int d;if(n!=O){

d=n%10;n=(n-d)/10;s=s+d;sumdig(n);

}else return(s);

}

(a) 12 6 (b)6 12

1

(c) garbage value

(c) 3 2 2

(c) -2 3 1 1

(c) 3 15

(d) error!!

(d) 0 0 0

(d) error

(d) error

f,

tbf

5.What would be the output of the following program.#define CUBE(x) (x*x*x)main(){

int a,b=3;a=CUBE(b++);printf("\n %d %d",a,b);

}

(a) 64 4 (b) 27 4

6. What would be the outputof the followingprogram.main(){

const int x=get();printf("%d",x);

}get(){

}return(20);

(a) 20 (b) garbage value

7. A function has this prototype void f1 (int **x),How will you call this function?

(a) int **a;f1 (a);

(b) int a;f1 (&a);

8. Pointoutthe error, if any, in the for loopmain(){

int 1=1;for(;;){

printf("%d", 1++);if(I>10)

break;}

}

(a) The condition in the for loop is a must(c) The for loop should be replaced by a while loop

9. Can the following piece of code be executed?char * my-strcpyO;

int main(void){

char strA[1O]="compile" ,strB[10];my-strcpy(strB,strA);puts(strB);

~ BRA~DRf-"iS

(c) 27 6 (d) 64 6

(c) error (d) 0

(c) int *a;f1 (&a);

(d) int a=5;f1 (&&a);

(b) The two semicolons should be dropped(d) No error

}char * my-strcpy(char *destination,char *source){

char *p=destination;while(*source!='\O'){

2 ..

( D7 ~*p++=*source++;

}*p='\O';return destination;

}

(a) Compilation will only give a warning but will proceed to execute & will display "compile"(b) The compilation error char *(char *,char *) differs in levels of indirection from 'intO' willow(c) Yes & it will print compile on the screen (d) None of the above

10. What would be the output of the following program.#include<stdio.h>mainO{

char str[5]="fast";static char *ptr_to_array = str;printf("%s",ptUo_array);

}

(a)Compilation will only give a warning but will proceed to execute & will display "fast"(b) display "fast" on screen (c) will give a compilation error (d) none of the above

11. What would be the output of the following program.mainO{

int num,*p;num=5;p=&num;printf("%d",*p);

}

(a) 6 (b) 5 (c) junk value (d) compilation error

12. What would be the output of the following program.mainO{

int a[3]={2,3,4};char *p;p=a;p=(char *)((int *)p+1);printf("%d",p);

}

(a) 2 (b) 0 (c) junk value (d) 3

13. What would be the output of the following program.mainO{

int i=10;fn(i);printf("%d", i);

}fn(int i){

}return ++i;

(a) 10 (b) 11 (c) 12 (d) Compilation erro

3 f',

ro1 \~ ?@14. What will be the value of i & j after the loop is executed?<BR> for(i=O,j=O;i<5,j<25;i++,j++)

(a) i=4,j= 24 (b) i=24,j= 24 (c) i=25,j= 25 (d) i=5,j=25

15. What would be the output of the following program.mainO{

int i,j;i=10;j=sizeof(++i);printf("%d",i);

(a) 11 (b) 10 (c) 4 (d) compilation error

16. What would be the output of the following program.mainO{

int i=7;printf("%d\n", i++*i++);

}

(a) 49 (b) 56 (c) 72 (d) compilation error

17. What will the printf print?mainO{

char *p,*fO;p=fO;printf("fO returns:%s\n",p);

}char *fO{

char result[80];strcpy(result,"anything will do");return (result);

}

(a) fO returns:anythingwill do (b) fO returns:(d)The printf statementis not goingto beexecuted

(c) compilation error

18. How many times the following program would print 'Jamboree'?mainO{

printf("\n Jamboree");mainO;

}

(a) infinite number of times (b) 32767 times (c) 6553times (d) till the stack does not overflow

4 f!,

tD7 ~ E3R R~ 0 R!-'i5

19. Noticethe error in the default statementin the code snippet below.WiIIit give a compilationerror?mainO{

int a=1 O,j;

j=fn(a);switch0){

case 30: printf("the value is 30");break;

case 50: printf("the value is 50");break;

defaultprintf("the value is not 30 or 50");}

}fn(int a){

}return (++a);

(a) Will display "the value is 30" (b) Will display "The value is not 30 or 50"(c) Yes a compilation error would happen(d) No compilation errors but there will be no output on the screen

20. What would be the output of the following program.mainO{

struct emp{

char name[20];int age;float sal;

};struct emp e = {"tiger"};printf("\n %d %f',e.age,e.sal);

}(a) 0 0.000000 (b) Garbage values (c) Error (d) none of the above

21. void fn(int *a, int *b){int *t;t=a;a=b;b=t;}

mainO{int a=2;int b=3;fn(&a,&b);printf("%d,%d", a,b);}

What is the output?(a) Error at runtime (b) Compilation error (c) 2 3 (d) 3 2

5 "

23. int mainO{

FILE *fp;fp=fopen("testdat","w");fprintf(fp,'hello\n");fclose(fp);fp=fopen ("testdat","w");fprintf (fp, "world");fclose(fp);return 0;

}

If textdat file is already present, after compiling and execution how many bytes does the fileoccupy?

(a) 0 bytes (b) 5 bytes (c) 11 bytes (d) data is insufficient

24. include<stdio.h>void swap(int*,int*);mainO

{int arr[8]={36,8,97,0, 161,164,3,9}for (int i=O; i<7; i++){

for (int j=i+1; j<8;j++)if(arr[i]<arr[j]) swap(&arr[i],&arr[j]);

}}

void swap(int*x,int*y){

int temp; static int cnt=O;temp= *x;*x=*y;*y=temp;cnt++;

}

What is cnt equal to

(a) 7 (b) 15 (c) 1 (d) none of these

25. f1 (int*x,intflag){

6 f

LO7 'GrBRRDRI""'iS

22. mainO{char *p="abc";char *q="abc123";while(*p=*q)printf("%c %c",*p,*q);}

(a) aabbcc (b) aabbcc123 (c) abcabc123 (d) infinite loop

r Dtp~

CDint *y;

*y=*x+3;switch(flag){

case 0:*x=*y+1 ;break;case 1:*x=*y;break;case 2:*x=*y-1 ;break;

}return(*y);

}

mainO{

int *x=5,i,j;i=f1(x,0); j=f1(x,1);printf("%d %d %d ",i,j,*x);

}What is the output?

(a) 8 8 8 (b) 5 8 8 (c) none of these (d) garbage value

26. What does the following function print?func(int i){

if(i%2) return 0;else return 1;

}mainO{

int i=3;i=func(i);i=func(i);printf("%d",i);

}

(a) 3 (b) 1 (c) 0 (d) 2

27. char*gO{

static char x[1024];return x;

}mainO{

char*g 1="First String";strcpy(gO,g1 );g1=gO;strcpy(g1, "Second String");printf("Answer is:%s", gO);

}(a) Answer is: First String (b) Answer is: Second String (c) Run time Error/Core Dump(d) None of these

7 *,

t b-' p~28. Output of the following program is

mainO{

int i=O;for(i=0;i<20;i++){

switch(i){case 0:

i+=5;case 1:

i+=2;case 5:

i+=5;default:

i+=4;break;

}printf("%d",i);

}}

(a) 5,9,13,17 (b) 12,17,22

29. mainO

int a[5]={1 ,3,6,7,0};int *b;b=&a[2];

}The value of b[-1] is

(a) 1 (b) 3

30. Given a piece of codeint x[10];int *ab;ab=x;

(c) 16,21

(c) -6

(d) syntax error.

(d) garbage value

(a) *(x+5) (b) x[5]

To access the 6th element of the array which of the following is incorrect?

(d) *(*ab+5)(c) ab[5]

Name:

/30

Question Answer

No. a bed

1 0000

2 0000

3 0000

4 0000

5 0000

6 0000

7 0000

8 0000

9 0000

10 0000

11 0000

12 0000

13 0000

14 0000

15 0000

r~tD 1 @) Roll No:

ANSWER CODING SHEET I Question Set No.107 I

Question

No.

Answer

16

17

a bed

00000000

0000

000000000000

00000000

0000

00000000

0000

0000

00000000

18

19

20

21

22

23

24

25

26

27

28

29

30

B R R~I 0 R i<"i'='

f',

Name:

/30

Question Answer

No. a bed

1 8000

2 0008

3 80004 0800

5 0080

6 8000

7 0080

8 0008

9 0080

10 0800

11 0800

12 0008

13 0800

14 0080

15 8000

r~\ 01 @ Roll No:

ANSWER CODING SHEET I Question Set No.107 I

Question

No.

16

20

21

22

23

Answer

17

18

19

a bed

08008000

0008

080080000800

00080800

0800

00080080

0800

0080

80000008

24

25

26

27

28

29

30

E3RR~IDRhS

fl