CA208 Test set3 (Answers) Question 1 la. struct employee{ [1] char name[31]; [1] char addr[41]; [1] int age; [1] float salary; [1] } ; b. struct empl,oyee empl[5]; [2] for(count=0; count<5; count++) [3] { strcpy(empl[count].name,', "); [1] strcpy(empl[count.addr, n "); [1] age = 0; [1] salary = 0.00; [1] } c. When a variable is the name of the array. An array name is also a pointer name.[2] d. Question 2 2a. #include <stdio.h> [0.5] int add (int,int); [1] int addl(int); [1] main( ) [0.5] int N; [1] printf("Please add a number to start adding"); scanf("%d",&N); [2] printf("`d",add(N,1)); [2] printf("`d",addl(N)); [2] return O; } b. int add(int n,int x) [1] { if (x<n) [1] return-add(n,x+l)+x; [2] else return n; [1] } c. int addl(int n) [1] { if (n>l) [1] return add(n-l)+n; [2] else return 1; [1] } Question 3 3a. No. [1] num is not an array name and therefore not a pointer[1]. iptr = #[1] b. Yes.[1] iptr will point to the first subscript 0 of number array [1]. c. Yes.[1] iptr = numb er;[~] d. 50 100 150 200 250 300 [10 ] e. The initial doesn't shift the pointer while latter does. The first one use the offset from the pointer. [3] Question 4 4a. #include<stdio.h> main() char s[] = {"Hello"); [1] int n; [1] for(n=0;*s != '\O';s++) [3] { n++; [1] printf("The string length of word is %d",n); [1] return O; } b. #include<stdio.h> main( ) { int arrl[10],arr2[10]; [2] int count; [1] for(count=0;count<10;count++) [3] arrl[count] = count + 1; [2] for(count=0; count<lO; count++) [3] arr2[count] = arrl[count]; [2] return O; } 5a. i=O; [1] while(i<10) [1] { counter++; [1] i++; [1] } i=O; [1] do [1] { counter++; i++; [2] }while(i<10); [1] b. A for-loop is a counter loop while a while-loop is a conditional loop. A while loop can definitely replace a for-loop but a for-loop may not be able to replace a while-loop. [2] A do-while loop will execute at least once before checking the condition while the while-loop will not execute if condition is not satisfied. [2] -- c. switch(x) [1] { case (x==10): [1] printf(nFull marks"); [1] break; [1] case (x==5): [1] printf("Just pass"); [1] break; [1] case (x < 5): [1] printf("Fail"); [1] break; [1] }