NEW
Font size
S
M
L
XL
WorksheetsSASI -1st year -DAY4-FN (21.12.23)
Total questions: 15
Worksheet time: 15mins
Name
Class
Date
1.
#include<stdio.h>
int main()
{
int arr[5], i=0;
while(i<5)
arr[i]=++i;
for(i=0; i<5; i++)
printf("%d, ", arr[i]);
return 0;
}
a)
1,2,3,4
b)
Garbage value, 1, 2, 3, 4,
c)
2,4
d)
none of these
2.
#include <stdio.h>
int main()
{
foo(ary);
}
void foo(int **ary)
{
int i = 10, k = 10, j = 2;
int *ary[2];
ary[0] = &i;
ary[1] = &j;
printf("%d\n", ary[0][1]);
}
a)
compile time error
b)
Runtime error
c)
Output : 20
d)
Undefined Behaviour
3.
#include<stdio.h>
int main()
{
int arr[1]={10};
printf("%d\n", 0[arr]);
return 0;
}
a)
1
b)
10
c)
6
d)
8
4.
#include <stdio.h>
void f(int a[][])
{
a[0][1] = 3;
int i = 0, j = 0;
for (i = 0;i < 2; i++)
for (j = 0;j < 3; j++)
printf("%d", a[i][j]);
}
void main()
{
int a[2][3] = {0};
f(a);
}
a)
0 3 0 0 0
b)
Junk junk junk
c)
Compile time error
d)
No output
5.
#include <stdio.h>
int main() {
int nums[3][2] = {{1, 2}, {3, 4}, {5, 6}};
printf("%d", nums[1][0] / nums[2][1]);
return 0;
}
a)
0
b)
1
c)
2
d)
3
6.
int arr[5] = {1, 2, 3, 4, 5};
int sum = 0;
for (int i = 0; i < 5; ++i) {
sum += arr[i] + i;
}
printf("%d", sum);
a)
Computes the average of the array elements
b)
Calculates the sum of array elements and their indices
c)
Finds the product of array elements and their indices
d)
Counts the number of odd array elements
7.
#include <stdio.h>
int main() {
int arr[5] = {1, 2, 3, 4, 5};
printf("%d", arr[2] / arr[4]);
return 0;
}
a)
0
b)
1
c)
2
d)
compiler error
8.
#include <stdio.h>
int main() {
int arr[5] = {1, 2, 3, 4, 5};
printf("%d", arr[1] * arr[3]);
return 0;
}
a)
2
b)
6
c)
8
d)
10
9.
#include <stdio.h>
int main() {
int arr[3][2] = {{1, 2}, {3, 4}, {5, 6}};
printf("%d", arr[2][1]);
return 0;
}
a)
1
b)
2
c)
5
d)
6
10.
#include <stdio.h>
int main() {
int nums[3][2] = {{1, 2}, {3, 4}, {5, 6}};
printf("%d", nums[1][1] - nums[0][0]);
return 0;
}
a)
1
b)
2
c)
3
d)
4
11.
int arr[5] = {1, 2, 3, 4, 5};
int product = 1;
for (int i = 0; i < 5; ++i) {
product *= arr[i] + i;
}
printf("%d", product);
a)
Computes the average of the array elements
b)
Calculates the sum of array elements and their indices
c)
Finds the product of array elements and their indices
d)
Counts the number of odd array elements
12.
int main()
{
int a[] = {1,2,3,4};
int b[4] = {5,6,7,8};
printf("%d,%d", a[0], b[0]);
}
a)
1,5
b)
2,6
c)
0,0
d)
compiler error
13.
int main()
{
char grade[] = {'A','B','C'};
printf("GRADE=%c, ", *grade);
printf("GRADE=%d", grade);
}
a)
GRADE=some address of array, GRADE=A
b)
GRADE=A, GRADE=some address of array
c)
GRADE=A, GRADE=A
d)
Compiler error
14.
int main()
{
float marks[3] = {90.5, 92.5, 96.5};
int a=0;
while(a<3)
{
printf("%.2f,", marks[a]); a++;
}
}
a)
90.5 92.5 96.5
b)
90.50 92.50 96.50
c)
0.00 0.00 0.00
d)
Compiler error
15.
int main()
{
int a[3] = {20,30,40};
int (*p)[3];
p=&a;
printf("%d", (*p)[0]);
}
a)
20
b)
0
c)
address of element 20
d)
Compiler error
Reset
