Anda di halaman 1dari 13

"We cannot solve our problems with the same thinking we used when we created them.

" - Albert Einstein

1 Programming in C TEST YOURSELF

1. Array passed as an argument to a function is interpreted as a. Address of the array. b. Values of the first elements of the array. c. Address of the first element of the array. d. Number of elements of the array

2. Which of the following statements correctly declare a function that receives a pointer to pointer to a pointer to a float and returns a pointer to a pointer to a pointer to a pointer to a float? a. float **fun(float***); b. float *fun(float**); c. float fun(float***); d. float ****fun(float***);

3. What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array? a. The element will be set to 0. b. The compiler would report an error.

c. The program may crash if some important data gets overwritten. d. The array size would appropriately grow. 4. The maximum combined length of the command-line arguments including the spaces between adjacent arguments is a. 128 characters b. 256 characters c. 67 characters d. It may vary from one operating system to another

5. In which stage the following code #include<stdio.h> gets replaced by the contents of the file stdio.h a. During editing b. During linking c. During execution d. During preprocessing 6. Which of the following function is more appropriate for reading in a multi-word string? a. printf(); b. scanf(); c. gets(); d. puts();

7. Which of the definition is correct? a. int length; b. char int; c. int long;

d. float double; 2

8. Point out the error in the following program. #include<stdio.h> int main() { void v = 0; printf("%d", v); return 0; } a. Error: Declaration syntax error 'v' (or) Size of v is unknown or zero. b. Program terminates abnormally. c. No error. d. None of these.

9. In C, if you pass an array as an argument to a function, what actually gets passed? a. Value of elements in array b. First element of the array c. Base address of the array d. Address of the last element of array

10. Which of the following is TRUE about argv? a. It is an array of character pointers b. It is a pointer to an array of character pointers c. It is an array of strings

d. None of above

Choose what is the output for the following code fragments of the c programs: 11. #include<stdio.h> void main() { char letter =`Z`; printf("\n%c",letter); } a. Z b. 90 c. Error d. Garbage Value

12. #include<stdio.h> void main() { int s=0; while(s++<10) { if(s<4 && s<9) printf("\n%d\t",s); } } a. 1 2 3 4 5 6 7 8 9 b. 1 2 3 10 continue;

c. 4 5 6 7 8 9 10 d. 4 5 6 7 8 9

"We cannot solve our problems with the same thinking we used when we created them." - Albert Einstein

13. #include <stdio.h> void main() { int I=3,*j,**k; j=&I; k=&j; printf("%d%d%d",*j,**k,*(*k)); } a. 444 b. 000 c. 333 d. 433

14. #include<stdio.h> main() {

struct { int i; }xyz; (*xyz)->i=10; printf("%d",xyz.i); } a. Program will not compile. b. 10 c. Address of i d. None of the above. 15. #include <stdio.h> main() { char str[]="S\065AB"; printf("\n%d", sizeof(str)); } a. 7 b. 6 c. 5 d. error

16. #include<stdio.h> void swap(int&, int&); void main() {

int a = 10,b=20; swap (a++,b++); printf("\n%d\t%d\t",a, b); } void swap(int& x, int& y) { x+=2; y+=3; } a. 14, 24 b. 11, 21 c. 10, 20 d. Error

17. #include<stdio.h> int main() { void fun(int, int[]); int arr[] = {1, 2, 3, 4}; int i; fun(4, arr); for(i=0; i<4; i++) printf("%d,", arr[i]);

return 0; }

a. 2, 3, 4, 5 b. 1, 2, 3, 4 c. 0, 1, 2, 3 d. 3, 2, 1 0

18. #include<stdio.h> int main() { enum days {MON=-1, TUE, WED=6, THU, FRI, SAT}; printf("%d, %d, %d, %d, %d, %d\n", MON, TUE, WED, THU, FRI, SAT); return 0; } a. -1, 0, 1, 2, 3, 4 b. -1, 2, 6, 3, 4, 5 c. -1, 0, 6, 2, 3, 4 d. -1, 0, 6, 7, 8, 9

19.

#include<stdio.h>

int main() { float i=10, *j; k=&i; void *k;

j=k; printf("%f\n", *j); return 0; } a. 10.000000 b. Compile error c. Run time error. d. None 25. What will be the output of the program (sample.c) given below if it is executed from the command line as #include<stdio.h> int main(int argc, char *argv[]) { int j; j = argv[1] + argv[2] + argv[3]; printf("%d", j); return 0; } a. 6 b. sample 6 c. Error d. Garbage value void fun(int n, int arr[]) { int *p=0; $ sample 1 2 3

int i=0; while(i++ < n) p = &arr[i]; *p=0; } "We cannot solve our problems with the same thinking we used when we created them." - Albert Einstein

26. #include<stdio.h> int main() { char ch; int i; scanf("%d", &ch);

scanf("%c", &i);

printf("%c %d", ch, i); return 0; } a. Error: suspicious char to int conversion in scanf() b. Error: we may not get input for second scanf() statement c. No error d. None of above

27. #include<stdio.h> (Consider integer is 4 bytes long.)

int main() { int ***r, **q, *p, i=8; p = &i; q = &p; r = &q; printf("%d, %d, %d\n", *p, **q, ***r); return 0; } a. 8, 8, 8 b. 4000, 4002, 4004 c. 4000, 4004, 4008 d. 4000, 4008, 4016 28. #include<stdio.h> int main() { int *x; *x=100; return 0; } a. Error: invalid assignment for x b. Error: suspicious pointer conversion c. No error d. None of above

29. #include<stdio.h> int main() { int a[] = {10, 20, 30, 40, 50}; int j; for(j=0; j<5; j++) { printf("%d\n", a); a++; } return 0; } a. Error: Declaration syntax b. Error: Expression syntax c. Error: Constant pointer changed. d. Error: Rvalue required 6 [PART D] (30) Complete the program as specified.

30. In the following program add a statement in the function fun() such that address of a gets stored in j?

#include<stdio.h> int main()

{ int *j; void fun(int**); fun(&j); return 0; } void fun(int **k) { int a=10; /* Add a statement here */ }

a. **k=a; b. k=&a; c. *k=&a d. &k=*a

Anda mungkin juga menyukai