Assignment-7 Solution July 2019
Assignment-7 Solution July 2019
Solution: (a) The valid initialization is option (a). Next two are invalid declaration because
the second dimension must be specified.
a) Matrix-Multiplication
b) Minimum Spanning Tree
c) Finding connectivity between nodes
d) All of the mentioned
Solution: (d) For all of the above cases, multi-dimensional arrays are used.
6. If the starting address of an float array Arr[10][10] is 2000, what would be the memory
address of the element Arr[5][6]? (float takes 4 bytes of memory)
a) 2268
b) 2120
c) 2224
d) 2144
Solution: (c) If ‘a’, ‘b’ and ‘c’ denotes the starting address, number of columns and size in
bytes for each element respectively of array Arr[][], then the location of Arr[i][j] can be
calculated as
ASSIGNMENT-7 SOLUTION
Solution: (b) In the initialization method of a multidimention array, it must have bounds for
all dimensions except the first.
a) fellows
b) h
c) fello
d) Compiler error
Solution: (a) a[2] indicates the 3rd string of the 2D array. Thus “fellows” will be printed.
10. If the two strings s1 and s2 are identical, then strcmp(char *s1, char *s2) function
returns
a) 1
b) -1
c) 0
ASSIGNMENT-7 SOLUTION
a) n1=18, n2=17
b) n1=18, n2=18
c) n1=17, n1=17
d) n1=17, n2=18
a) gnirts
ASSIGNMENT-7 SOLUTION
b) gnirt
c) string
d) no output is printed
Solution: (d)
Let us consider below line inside the for loop p[i] = s[length — i];
For i = 0, p[i] will be s[6 - 0] and s[6] is ‘\0′
So p[0] becomes ‘\0’. It doesn’t matter what comes in p[1], p[2]….. as P[0] will not change
for i >0. Nothing is printed if we print a string with first character ‘\0′
13. What will be the value of ‘i’ after the execution of the C code given
below?
#include<stdio.h>
#include<string.h>
int main()
{
static char str1[] = "dills";
static char str2[20];
static char str3[] = "daffo";
int i;
i = strcmp(strcat(str3, strcpy(str2, str1)), "daffodills");
return 0;
}
a) 0
b) 1
c) -1
d) None
Solution: (a) 0
strcat(str3, strcpy(str2, str1)) makes it “daffodills”, hence strcmp(“daffodills”, “daffodills”)=0
Solution: 321004
ASSIGNMENT-7 SOLUTION
In a[2][3] = {1, 2, 3, 4}; only 4 values are given. The rest will be taken as 0. So, finally
a[2][3] = {{1, 2, 3}, {4,0,0}}; So, 321004 will be printed as per the given for loop.