Section 1: Technical Reasoning 1) Often a good database design is one that is normalized. What could be the disadvantages of normalization? (2m) 2) Why is the virtual keyword (used in C++) or an equivalent not required in Java? (2m) 3) Assume a computer laboratoryis assigned a class C block of addresses with net id 192.168.100. What is the maximum number of students that can be accommodated in the laboratory (if every student is given a computer with an IP assigned to it) and why? (2m) (Hint: Not all addresses from 192.168.100.0 to 192.168.100.255 can be assigned to computers. Some are reserved for certain reasons) 4) The C function below is written to swap the contents of two indices in an array. Unfortunately, it fails in a particular case. When does it fail? (4m) void swap(int *S, int i, int j) { S[i] ^= S[j] ^= S[i] ^= S[j]; } 5) The C++ function below has a bug (although the code compiles). What is it? (3m) How can it be resolved? (Rewrite the bug free code)(3m) (Assume the maximum length of str is 2045) char*copyAlternatives(char *str) { char copy[1024]; int i; for(i = 0; i <strlen(str); i += 2) { copy[i/2] = str[i]; } copy[i / 2] = ‘\0’; return copy; } Section 2: Programming Challenge 1) What is the output of the following program? (4m) (***) void fun(char *a) { if(*a!='\0') { fun(a+1); printf("%s ",a); fun(a+1); } } int main() { fun("abcd"); } 2) Write the condition which will result in the code printing “Hello World”. There are two solutions. What are the two? (4m) if(CONDITION) { printf(“Hello “); } else { printf(“World”); } 3) Write a C++ program which will print 1 to 10000. You are not allowed to use any loop constructs, nor function calls. (6m) 4) Write a function void swap(int *S, int i, int j); which swaps S[i] and S[j] without using the temp variable. If the function contains only one statement, you will be awarded full marks. (3m) 5) Write a function void diamond(int base); which prints a diamond of stars with base length ‘base’. (7m)If the call is base(5), it should print * *** ***** *** * SECTION 3: C Puzzles 1) What will be the output of the program ? #include<stdio.h> int main() { int i, a[] = {2, 4, 6, 8, 10}; change(a, 5); for(i=0; i<=4; i++) printf("%d, ", a[i]); return 0; } change(int *b, int n) { int i; for(i=0; i<n; i++) *(b+1) = *(b+i)+5; } A. 7,9,11,13,15 C. 2,4,6,8,10 B.2,15,6,8,10 D.3,1,-1,-3,-5 2) What is the output of the program? int main() { #include<stdio.h> #include<conio.h> char *_[20] = {"typical program"}; clrscr( ); *_=(char *)malloc(100); printf("%s",*_); printf("%s",_); return 0; } (a). include is not allowed inside main() (b). Illegal declaration of *_ (c). garbage value (d). typical program 3) What is the output of the following program? int main() { char message = {'h','o','w','n','i','c','e','?'}; printf("age = %s",message); return 0; } (a). age = junkvalue (b). age = hownice? (c). age = h (d). error 4) What is the output of the following program? # include<stdio.h> int foo(int a) { return (a<<(a%2)&a); } int main() { int result; result = foo(7); printf("%d",result); return 0; } (a). 3 (b). 6 (c). 1 5) What will be the output of the following program? int main() { char b[20]={1,2,3,4,5}; int x; for(x=0;x<5;x++) { b[x]=x+'a'; } (d). 0 printf("%s",b); return 0; } (a). 12345 (b). abcde (c). a2345 (d). error 6) What will be the output of the following program? int main() { int x=3; while(x--); { int x=4; x--; printf("%d",x); } return 0; } (a). 4321 (b). 3210 (c). 321 (d). 3 7) Point out the error in the following program. float a = 3.56; void main() { float b; b = a % 3; printf (“%f”,b); } A. 0.56 B. Results in a compiler error C. Results in a linker error D. Depends on the compiler 8) What is the output of this program #include main() { int k = 5; if (++k < 5 && k++/5 || ++k <= 8); printf("%d\n", k); } A.7 B.11 C.8 D.9 9) What is the output of this program #include<stdio.h> int main() { int i=0,j=0; while(i<100) { if((i&(i+1))==0) j+=i; i++; } printf("%d ",j); } A) 120 B) 64 C) 256 D) 128 10) What is the output of the program? #include <stdio.h> void main(){ int a=1, b=2, c=3; a = b << c; printf("%d\n",a);} 16 32 8 2 11) What is the output of the program? main() { int x,y; x=9;y=8; if(x++,y++) printf("%d,%d",x+y,y); return 0; } (a). 18,8 (b). 18,9 (c). 19,8 (d). 19,9 12) What is the output of the program? #include <stdio.h> void main() { static int x=1; int res=0; do { res=(1/x); printf("%d ",res); }while(0<x--); } (a). Endless loop (b). Divide by zero error (c). 1 Divide by zero error (d). No error 13) What is the output of the program? #include <stdio.h> void main() { int a=0,b,x,y; b=~0;x=-1;y=-0; if(b==x) printf(" 1 "); else printf(" 2 "); if(b==y) printf(" 3 "); else printf(" 4 "); } (a). 1,4 (b). 2,4 (c). 1,3 (d). 2,3 14) What is the output of the following program? #include <stdio.h> struct x { int x:8; float y; char d; }sx; struct y { int x:9; float y; char d; }sy; void main() { printf("%d",sizeof(sx)); printf(",%d",sizeof(sy)); } (a). 7,8 (b). 13,14 (c). 6,7 (d). 7,7 15) What is the output of the following program? #include <stdio.h> void main() { fn(5); } int fn(int x) { if(x<=0) return; else fn(x-1)+x; printf(" %d ",x); return; } (a). returns nothing (b). 1 2 3 4 5 (c). error (d). 5 4 3 2 1 16) What will be the output of the following program? #include <stdio.h> void main() { int bat[5]={1,2,3,4,5},*bate; bate=&bat[5]; printf("%d",bate[-1]); } (a). 5 (b). 4 (c). 3 (d). 2 17) What will be the output of the following program? #include <stdio.h> void main() { unsigned int a=0; while(a>=0) { printf(" %u ",a); a--; } } (a). 0,65535,65534,... (b). empty screen (c). 0,65535,65533,... (d). 0,65534,65532,... 18) Give the output of the program? main() { int x,y,z; scanf("%d%d",x,y); z=x+y; printf("%d",z); return 0; } Give input values: x=2,y=3 (a). 5 (b). will not compile (c). empty screen (d). garbage value 19)What is the output of the program? void main() { int bit, byte=0x5; bit = 1; switch(bit & byte) { case 3: printf("hai!\t"); case 2: printf("everybody\t"); case 1: printf("fine"); default:printf(""); } } (a). hai! everybody (b). everybody fine (c). fine fine (d). empty screen 20) Select the appropriate answer(1) #define swap(x,y) int a;\ a =x;\ x = y;\ y = a; int main() { int a =5,b=6; swap(a,b); printf("%d,%d",a,b); } A. 5 6 B. 6 5 C. Runtime error D. Compile error 21) What is the output of the program? main() { int a=6; char arr[a]="lird"; arr[a-1]="l"; arr[a-2]="i"; arr[a-3]="r"; arr[a-4]="d"; printf("%s",arr); return 0; } (a). error: constant expression required (b). error: non portable pointer inclusion (c). lidril (d). both (a) and (b) 22) What is the output of the program? main() { int i=3; do{ i--; printf("Hai"); continue; }while(i); return 0; } (a). HaiHaiHai (b). HaiHai (c). The Loop will not end (d). Hai 23) What will be the output of the following program? main() { int x=99; int a=90,b=10; x = sum(a,b) == x ; printf("%d,",x); x = sum(b,a) == 100; printf("%d",x); return 0; } sum(int a,int b) { int c; c=a+b; return c; } (a). 0,0 (b). 99,100 (c). 100,100 (d). 0,1 24) What is the output for this program ? #include<stdio.h> #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0])) int array[] = {23,34,12,17,204,99,16}; int main() { int d; for(d=-1;d <= (TOTAL_ELEMENTS-2);d++) printf("%d",array[d+1]); return 0; } a)00000000 c)compiler error b)233412172049916 d)no output 25) What is the output of the following program if the following function is called with 4 as arguement? void fun(int n) { if(n>0) { fun(--n); cout<<n; fun(--n); } } a)0120 b)4321121 c)0120301 d)Infinite loop 26) What is the output for the following program ? #include<stdio.h> int main() { char a[]="\0"; if(printf("%s",a)) printf("Hello Earth!\n"); else printf("Hello Moon!\n"); } a)Hello Earth! b) Hello Moon! d) Implementation Defined c) Undefined Behaviour 27) What does the following program print? #include<stdio.h> void f(int *p,int *q) { p=q; *p=2; } int i=0,j=1; int main() { f(&i,&j); printf("%d%d\n",i,j); } a)22 b) 21 28) What is the output of the program? c) 01 d) 02 main() { unsigned int fix; int bug = -25; fix = -25; if (fix==bug) printf("You fool"); else printf("%d",((-fix) + (-bug))); return 0; } (a). you fool (b). 50 (c). 0 (d). error 29) What will be the output of the following program? #include<stdio.h> int f(int *a,int n) { if(n<=0) return 0; else if(*a%2 == 0) return *a+f(a+1,n-1); else return *a-f(a+1,n-1); } int main() { int a[]={12,7,13,4,11,6}; printf("%d",f(a,6)); } a)-9 19 b) 5 30) What will be the output of the following program? main() { char c='a'; # include<stdio.h>; printf("%c",c); return 0; } (a). compilation error (b). a (c). c (d). runtime error c) 15 d)