Assignment 6 July 2022 Solution
Assignment 6 July 2022 Solution
Solution: (b)
2. An integer array of dimension 10 is declared in a C program. The memory location
of the first byte of the array is 1000. What will be the location of the 9th element of
the array? (Assume integer takes 4 bytes of memory and the element stored at 1000
is identified as 1st element)
a) 1028
b) 1032
c) 1024
d) 1036
Solution: (b) Integer takes four bytes of memory. As the memory assignment to the
elements are consecutive and the index starts from 0, the 9th element will be located at
1000+(8×4)
a) 1
b) 2
c) 3
d) 4
Solution: (a) The program finds the minimum element of an array. Hence, the output
is 1.
5. What actually gets passed when you pass an array as an argument to a function
a) 5, 4
b) 5, 5
c) 4, 4
d) 3, 4
Solution: (c)
a) 5
b) 6
c) 9
d) 10
Solution: (c)
x[i] is equivalent to *(x + i),
so (buf + 1)[5] is *(buf + 1 + 5), i.e. buf[6]=9.
10. How many ‘a’ will be printed when the following code is executed?
#include <stdio.h>
int main()
{
int i = 0;
char c = 'a';
while (i < 5)
{
i++;
Week 6 Assignment Solution
switch (c)
{
case 'a':
printf("%c ", c);
break;
}
}
printf("a\n");
return 0;
}