Sie sind auf Seite 1von 8

Chapter - 6 Arrays & Strings

1. Which is the following statement are correct regarding arrays? i) Array elements are stored in contiguous memory locations ii) Size of array can be mentioned anywhere in the program iii) The Expression arr[i] refers to i+1 element in array arr 1) All are true 2) i only 3) i and iii 4) Nothing is true

2. What is used to access individual element of an array? 1) ( ) 2) [ ] 3) { } 4) ->

3. What is true about size of an array? 1) 2) 3) 4) There is no limit on size of array Size of array must be fixed (constant) Size can be omitted if array is initialized All are true

4. What can not be used for initializing array? 1) ' ' 2) 3) { } 4) [ ]

5) Indexing of array starts from 1) 1 2) size-1 3) 0 4) depends on compiler

6. What is maximum size possible for array of char? 1) 128 2) 256 3) 65535 4) no limit (entire memory)

7. What is true about array name? 1) 2) 3) 4) Array name is a variable pointer storing starting address of an array Array name is a constant pointer storing starting address of an array Array name is a constant pointer storing addresses of all array locations Array name is not a pointer 4) array

8. There can not be array of _________. 1) void 2) structure 3) pointer 9. What is minimum size possible for an array?

1) 0

2) 1

3) 2

4) none

10. ________dimensional array is not possible. 1) 0 2) 2 3) 3 4) 6

11. A[j] is not same as________. 1) *(A+j) 2) *(j+A) 3) j[A] 4) A+j

12. int num[5]; Num[5] What is true about above two statements? 1) 1st statement indicates element & 2nd indicates array size 2) 1st statement indicates array size & 2nd indicates element 3) Both statements indicate array size 4) Both statements indicate element of an array 13. Arrays can be initialized provided they are________. 1) auto 2) static 3) extern 4) all of these

14. Array can be passed to function by passing its________. 1) values 2) address 3) both 1 & 2 4) None of these

15.Which of the following statements are correct regarding arrays : i) Array is a collection of similar type of elements ii) Array is a group of same type of variables iii) Array has sequential storage 1) all are true 2) iii only 3) i and iii 4) ii and iii

16. Which header file should be included for using standard string functions? 1) string.c 2) stdlib.h 3) stdio.h 4) string.h

17. String constant is enclosed in 1) 18. String ends with 1) NULL 2) \0 3) 0 4) \\0 2) 3) { } 4) \* *\

19. To store string, array of _______is required

1) char

2) int

3) void

4) string

20. If we print \0, what is seen? 1) \0 2) \\0 3) blank 4) Error : can not print \0

21) Which is not a standard string function in C? 1) strset 2) strtok 3) strrchr 4) strno

22. Which is not a standard function used for string comparison? 1) strncmp 2) stricmp 3) strnicmp 4) strncmpi

23. Which function can be used to find last accurrence of a character in a string? 1) strchr 2) strrchr 3) strlchr 4) strrevchr

24. void main( ) { int a[ ]={20,30,40,50,60}, *j=a; j+=3; printf(%d,*j); } 1) 50 2) 20 3) 40 4) Compilation error

25. void main( ) { char p[5]={0,0,65,66}; printf(%d %d, p[1], p[4]); } 1) 0 66 2) 0 0 3) 0 garbage 4) Error

26. void main( ) { char a[12]={S,u,n, C,o,m,p,u,t,e,r}; printf(%s, a); } 1) Sun 2) SunComputer 3) Sun Computer garbage 4) Error

27. void main( ) { int a[ ]={10,20,30,40,50}, j; for(j=0; j<5; j++) printf(%d,*a); }

1) 2) 3) 4)

10 10 10 10 10 10 20 30 40 50 Garbage value printed 5 times Error : L value required

28. void main( ) { char a[6*3/2]={a, b, r, d, c}; printf(%c, a[3] ); } 1) r 2) d 3) c 4) Compilation error

29. void main( ) { int n[3][3]={2,4,6,8,5,3,5,1}, *ptr ,i; Ptr=&n[1][0]; for(i=0;i<=3;i++) printf(%d, *(ptr+i)); } 1) 8 5 3 5 2) 5 3 5 1 3) 3 6 8 5 4) 6 3 garbage garbage

30. void main( ) { int a[ ]={10,20,30,40,50}, i,*k; k=&a[3]-3; for (i=0;i<=4;i++) { printf(%d, *k); } 1) 10 20 30 40 50 2) 10 20 30 40 31. char *fun( ) { char result[100]="Hello world"; strcpy(result, Anything is Good); return result; } void main( ) {char *j; j=fun( ); printf(%s, j); } 1) Anything is Good 2) Hello world

k++;

} 4) Error

3) 10 20 30

3) Garbage

4) Compilation Error

32. void main( ) { char *dest,*source=SUN ITS; dest=malloc(strlen(source)); strcpy(dest, source); printf(%s, dest); free(dest);

} 1) free( ) fails 3) SUN ITS 2) strcpy( ) fails to copy string 4) Compilation error

33. void main( ) { char names[]={Aditi, Satish, Dipti, Sohan, Mohan}; char *t; int i; t=names[3]; names[3]=names[4]; names[4]=t; for(i=0;i<=4;i++) printf(%s names[i]); } 1) 2) 3) 4) Aditi Satish Dipti Mohan Mohan Aditi Satish Dipti Mohan Sohan Aditi Satish Sohan Dipti Mohan Error

34. void main( ) { int i, fun1( ), fun2( ), fun3( ); int (*f[3])( ); f[0]=fun1; f[1]=fun2; f[2]=fun3; for(i=0;i<3;i++) (*f[i]) ( ); } fun1( ) { printf(SUN); fun2( ); } fun2( ) { printf(COMPUTER); } fun3( ) { printf(EDUCATION); } 1) 2) 3) 4) SUN COMPUTER EDUCATION SUN COMPUTER SUNCOMPUTERCOMPUTEREDUCATION Error

35. void main( ) { int s[2][ ]={3,4,5,6,7,8,9,10}; printf(%d, s[1][2] ); } 1) 8 2) 9 3) 6 4) Error

36. void main( ) { int M[12]; M[0]=-12; M[11]=-12; printf(%d %d %d, *(M+0), *(M+11), *M ); } 1) -12 12 -12 2) -12 -12 -12 3) -12 -12 12 4) 0 11 garbage

37. void main( ) { int i=10; char ch='F', str[10]=" Born To Code"; sprintf(str,"%d %c",i, ch); printf("%s",str); } 1) Born To Code 2) 10 F BornToCode 3) 10 F 4) Error

38. void main( ) { int ary[2]; ary[-2]=2; printf(%d, ary[2-4] ); } 1) 2 2) 2-4 3) garbage 4) Error

39. void main( ) { char dac[ ]; dac[0]=65; printf(%c, dac[0] ); } 1) 65 2) a 3) A 4) Error

40 void main( ) { char sun[1]={2}; sun++; printf(%d, sun ); } 1) 3 2) 51 3) garbage 4) Error

1. int *P[20]; What is the size of array P in bytes? 1) 20*sizeof(int) 2) 20 3) 20*sizeof(int*) 4) 40

2. int a[50], *pa=a; To access 6th element in the array, which of the following statement is incorrect?

1) *(a+5)

2) (*pa+5)

3) pa[5]

4) None of these

3. void main( ) { int a[5]={1,3,6,7,0}, *p=&a[2]; print(%d,p[-1]; } 1) 1 2) 3 3) -6 4) 7

4. fun(int x, int *y) {x=*(y)+=2; } void main( ) { int a[5]={2,4,6,0},i, b=5; For(i=0;i<3;i++) {fun(a[i],&b); print(%d, b); } 1) 4 6 8 2) 7 9 11 3) 5 7 9 4) 5 5 5

5. // consider 32bit OS void main( ) { char *mess[]={Sun ITS, Sun CET, Sun BCS }; print(%d %d, sizeof(mess), sizeof(mess[1])); } 1) 8 2 2) 16 4 3) 4 2 4) None of these

6. junk(int i, int *j) { i=i*i; *j= *j * *j; } void main( ) { int i=-5, j=-2; junk(i, &j); printf(i=%d j=%d,i,j); } 1) i=25 j=4 2) i=-5 j=-2 3) i=-5 j=4 4) i=5 j=4

7. void main( ) {char *string; char *copystring( ); char source[]=SUN IT SCHOOL; char target[15]; string=copystring(target, source); printf(\n %s, string); }

char *copystring(char *t, char *s) {char *r=t; while(*s!=\0) { *t=*s; t++; s++;} *t=\0; return r } 1) SUN IT SCHOOL 8. void main( ) { int A[2]= {1, 2}; A[1-2]=50; Printf(%d, 1[A] ); } 1) 1 2) 2 3) 50 4) Error 2) No output 3) Garbage output 4) Error

9. int size=5; void main( ) { int Array[size+1]; printf(%d, sizeof(Array) ); } 1) 2 2) 6 3) 12 4) Error

10. void main ( ) { int str[4]= {1, 2, 3,0}; printf(%s, str ); } 1) 123 2) 1230 3) 1

4) 1230garbage