Day 2 - C Programming Test
Day 2 - C Programming Test
3.Output of the following program: #include<stdio.h> int main() { enum status { pass, fail, atkt}; enum status stud1, stud2, stud3; stud1 = pass; stud2 = atkt; stud3 = fail; printf("%d, %d, %d\n", stud1, stud2, stud3); return 0; }
A. C. 0, 1, 2 0, 2, 1 B. 1, 2, 3 D. 1, 3, 2
4. Can you combine the following two statements into one? char *p; p = (char*) malloc(100);
A. B. C. D. char p = *malloc(100); char *p = (char) malloc(100); char *p = (char*)malloc(100); char *p = (char *)(malloc*)(100);
9. What will be the output of the program #include<stdio.h> int main() { int i=3, *j, k; j = &i; printf("%d\n", i**j*i+*j); return 0; }
A. C. 30 9 B. D. 27 3
10. What will you do to treat the constant 3.14 as a long double?
A. C. use 3.14LD use 3.14DL B. D. use 3.14L use 3.14LF
11. What will be the output of the program If the integer is 4bytes long?
#include<stdio.h> 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. C. 8, 8, 8 4000, 4004, 4008 D. B. 4000, 4002, 4004 4000, 4008, 4016
12. Will the program compile? #include<stdio.h> int main() { char str[5] = "IndiaBIX"; return 0; }
A. True B. False
15. Will the following functions work? int f1(int a, int b) { return ( f2(20) ); } int f2(int a) { return (a*a); }
A. Yes B. No
16. What will be the output of the program? #include<stdio.h> int main() { int i; i = printf("How r u\n"); i = printf("%d\n", i); printf("%d\n", i); return 0; }
A. How r u 7 2
B.
C.
D.
19. #include<stdio.h> int main() { char p[] = "%d\n"; p[1] = 'c'; printf(p, 65); return 0; }
A. C. A c B. D. a 65
23.
A. B. C. D.
26.
27.
A. B. C. D.
Using goto inside for loop is equivalent to using (more than one answers possible)
continue break return none of the above
28.
A. B. C. D.
If func is a function needing three arguments a1, a2 and a3, then func can be invoked by
func(a1, a2, a3); *func(a1, a2, a3); (*func) (a1, a2, a3); All the above
29. The output of the following program main() { int a = 1, b = 2, c = 3; printf( %d, a += (a += 3, 5, a)); }
A. B. C. D. 8 12 9 6
30.
Write a program to swap two numbers using bitwise operators. Write a function in C called my 2DAlloc which allocates a two-dimensional array. Minimize the number of calls to malloc and make sure that the memory is accessible by the notation arr[i][j]
The weekly hokey match records of hokey team is kept by using the following structure: Name of the opponent (the other team) Number of goals scored Number of goals received DATE of the match (Assume that DATE is another type which contains day, month and year) Create a new data type, HOKEY, to represent the data structure of such a record. Note that DATE data type must also be created.