Font size
WorksheetsQuiz-5 AI
Total questions: 111
Worksheet time: 1hrs 20mins
How do you initialize an array in C?
int arr[3] = (1,2,3);
int arr(3) = {1,2,3};
int arr[3] = {1,2,3}
int arr(3) = (1,2,3)
What is the output of C Program.?
int main()
{
int a[] = {1,2,3,4};
int b[4] = {5,6,7,8};
printf("%d,%d", a[0], b[0]);
}
1
2
4
Error
What is the output of C Program.?
int main() {
int a[] = {1,2,3,4};
int b[4] = {5,6,7,8};
printf("%d,%d", a[0], b[0]);
}
1,5
2,6
0,0
Error
What is the output of C Program.?
int main()
{
char grade[] = {'A','B','C'}; printf("GRADE=%c, ", *grade); printf("GRADE=%d", grade);
}
GRADE=some address of array, GRADE=A
GRADE=A, GRADE=some address of array
GRADE=A, GRADE=A
Compiler error
What is the output of C program.?
int main() {
char grade[] = {'A','B','C'}; printf("GRADE=%d, ", *grade); printf("GRADE=%d", grade[0]);
}
A A
65 A
65 65
None
What is the output of C program.?
int main()
{
float marks[3] = {90.5, 92.5, 96.5};
int a=0;
while(a<3)
{
printf("%.2f,", marks[a]); a++;
}
}
90.5 92.5 96.5
90.50 92.50 96.50
0.00 0.00 0.00
Compiler error
What is the output of C Program.?
int main() {
int a[3] = {10,12,14};
a[1]=20;
int i=0;
while(i<3)
{ printf("%d ", a[i]);
i++; }
}
20 12 14
10 20 14
10 12 20
Error
What is the output of C program.?
int main() {
int a[3] = {10,12,14};
int i=0;
while(i<3)
{ printf("%d ", i[a]);
i++; }
}
14 12 10
10 10 10
10 12 14
None
What is the output of C program with arrays.?
int main() {
int a[3] = {20,30,40};
int b[3];
b=a;
printf("%d", b[0]);
}
20
30
address of 0th element.
Compiler error
What is the output of C program with arrays and pointers.?
int main() {
int a[3] = {20,30,40};
int *p[3];
p=&a;
printf("%d", *p[0]); }
20
address of element 20
Garbage value
Compiler error
float stats[3];
What is the range of the index?
{2, 3, 5, 8, 9, 11};
How would you access the fourth element in nums
numbers[i] = 2 * i + 1;
// Which index of the array holds the value of 5?
float average [20];
average[20] = 15.25;
float values[ ][ ] =
{ {1.2, 9.0, 3.2},
{9.2, 0.5, 1.5, -1.2},
{7.3, 7.9, 4.8} } ;
what is in values[2][1]?
float values[ ][ ] =
{ {1.2, 9.0, 3.2},
{9.2, 0.5, 1.5, -1.2},
{7.3, 7.9, 4.8} } ;
what is in values[3][0]?
int items[ ][ ] =
{ {0,1,3,4} , {4,3,99,0,7} , {3,2} } ;
Which of the following statements replaces the 99 with 77?
(a)
8
2
9
Error
No output
1
2
No output
Compilation Error
1 followed by garbage value
1 1 1
1 0 0
Error
0
1
5
garbage value
Error
1,2,3
4,5,6
5,7,9
Error
0
1
2
3
Error
30 30 garbage value
30 30 30
30 20 garbage value
30 60 40
Garbage value
0
1
Compiler dependent
(a)
(a)
(a)
How to initialize an array in C? tick all the correct statement.
int arr[3] = {1,2,3}
int arr(3) = {1,2,3};
int arr(3) = (1,2,3);
int arr[3] = (1,2,3);
int arr[3] = {0}
What will be the output after execution of the program?
(a)
Assuming int is of 4 bytes, what is the size of int arr[12];?
(a)
What is Array?
A. Collection of different type of elements
B. Collectionof similar type of elements
C. None of the above
D. Both A and C
What is right way to Initialize array?
A. int num[6] = { 2, 4, 12, 5, 45, 5 };
B. int n{} = { 2, 4, 12, 5, 45, 5 };
C. int n{6} = { 2, 4, 12 };
D. int n(6) = { 2, 4, 12, 5, 45, 5 };
What is the maximum number of dimensions an array in C may have?
A. Two
B. eight
C. sixteen
D. Theoratically no limit. The only practical limits are memory size and compilers
Which of the following function is more appropriate for reading in a multi-word string?
scanf()
gets()
printf()
puts()
What is the starting index of an array in C?
0
1
5
4
String is a
Array of characters
Array of integers
Array of double
All
strcat()
concatenates two strings
Compare two strings
find length
all
Finds the string length
strcmp()
strcpy()
strlen()
all
(a)
(a)
(a)
Compilation Error
14
13
Garbage Value
321004
3210
01234
400123
432100
1 2 3 4 5 5
1 2 3 4 5 0
1 2 3 4 5 Garbage value
Error
int A[5][4];
What will be the size of above array element ?
(a)
Below is an example of -
int no[30][4];
1-D Array
2-D Array
3-D Array
4-D Array
int A[2][2][2];
What will be the size of above array element ?
(a)
Pick all correct statements.
int A[][]={1,2,3,4};
int A[2][]={1,2,3,4};
int A[][2]={1,2,3,4};
int A[2][2]={1,2,3,4};
How do you initialize an array in C?
int arr[3] = (1,2,3);
int arr(3) = {1,2,3};
int arr[3] = {1,2,3}
int arr(3) = (1,2,3)
What is the output of C Program.?
int main() {
int a[] = {1,2,3,4};
int b[4] = {5,6,7,8};
printf("%d,%d", a[0], b[0]);
}
1,5
2,6
0,0
Error
What is the output of C program.?
int main()
{
float marks[3] = {90.5, 92.5, 96.5};
int a=0;
while(a<3)
{
printf("%.2f,", marks[a]); a++;
}
}
90.5 92.5 96.5
90.50 92.50 96.50
0.00 0.00 0.00
Compiler error
What is the output of C Program.?
int main() {
int a[3] = {10,12,14};
a[1]=20;
int i=0;
while(i<3)
{ printf("%d ", a[i]);
i++; }
}
20 12 14
10 20 14
10 12 20
Error
What is the output of C program.?
int main() {
int a[3] = {10,12,14};
int i=0;
while(i<3)
{ printf("%d ", i[a]);
i++; }
}
14 12 10
10 10 10
10 12 14
None
What is the output of C program with arrays.?
int main() {
int a[3] = {20,30,40};
int b[3];
b=a;
printf("%d", b[0]);
}
20
30
address of 0th element.
Compiler error
An array elements are always stored in ________ memory locations.
sequential
Random
Sequential and Random
None of the above
8.Which of the following correctly accesses the seventh element stored in arr, an array with 100 elements?
arr[6]
arr[7]
arr{6}
arr{7}
What is the minimum and maximum Indexes of this below array.?
int main()
{
int ary[9];
return 0;
}
-1, 8
0, 8
1,9
None of the above
What is the output of this program
#include <stdio.h>
int main()
{ int a[2][] = { {1,1,1},{2,2,2}};
printf("%d", a[1][1]);
}
1
Error
2
0
numbers[i] = 2 * i + 1;
// Which index of the array holds the value of 5?
#include <stdio.h>
int main()
{
int arr[5];
// Assume base address of arr is 2000 and size of integer is 32 bit
printf("%u %u", arr + 1, &arr + 1);
return 0;
}
What is the o/p of the program?
2004 2020
2004 2004
2004 Garbage value
The program fails to compile because Address-of operator cannot be used with array name
Which of the following statements are correct about an array?
1:The array int num[26]; can store 26 elements.
2:The expression num[1] designates the very first element in the array.
3:It is necessary to initialize the array at the time of declaration.
4:The declaration num[SIZE] is allowed if SIZE is a macro.
1
1,4
2,4
2,3
Which of the following gives the memory address of the first element in array foo, an array with 100 elements?
foo[0];
foo;
&foo;
foo[1];
Arrays are structures that hold multiple variables of the _____________ data type
int data type
char data type
same data type
different data type
Predict output of following program
int main(){
int i;
int arr[5] = {1};
for (i = 0; i < 5; i++)
printf("%d ", arr[i]);
return 0;
}
1 1 1 1 1
1 followed by 4 junk values
1 0 0 0 0
Compiler error
What is the output of the following program?
int main()
{
int i; int arr[5] = {0};
for (i = 0; i <= 5; i++)
printf("%d ", arr[i]);
return 0;
}
Compiler error : Array index out of bound
Prints 0 five times followed by garbage value
Program will crash
The program may print 0 five times followed by garbage value, or may crash if address (arr+5) is invalid
What will be the output of the following code if array elements are: 5, 8, 9, 6, 1, 7, 2?
for(i=0, j=6; i<=(7/2) ; i++, j-- )
print(" %d - %d", array[i], array[j] )
5 8 9 6 - 2 7 1 6
5 8 9 6 -
6 1 7 2
Error
5 - 2
8 - 7
9 - 1
6 - 6
What will be the output of:
int a[] = { 5, 4, 3, 2, 1};
int i;
for(i=0; i>=3; i++)
printf("%d \n", a[ i ] );
5 4 3 2 1 - one in each line
5 4 3 2 - one in each line
No output
Never ending loop
What is the output of C Program.?
int main() {
int a[];
a[4] = {1,2,3,4};
printf("%d", a[0]); }
1
2
4
Compiler Error
What is the maximum number of dimensions an array in C may have?
2
8
20
50
Theoratically no limit. The only practical limits are memory size and compilers.
The parameter passing mechanism for an array is
call by value
call by reference
call by value-result
None of the above
When does the ArrayIndexOutOfBoundsException occur?
Compile-time
Run-time
Not an error
Not an exception at all
2,1,15
1,2,5
3,2,15
2,3,20
5
4
6
7
A one dimensional array A has indices 1....75.Each element is a string and takes up three memory words. The array is stored starting at location 1120 decimal. The starting address of A[49] is
1167
1164
1264
1169
If storage class is missing in the array definition, by default it will be taken to be
automatic
external
static
either automatic or external depending on the place of occurrence
he following program
main( )
{
static int a[ ] = { 7, 8, 9 } ;
printf( "%d", 2[ a ] + a[ 2 ] ) ;
}
results in bus error
results in segmentation voilation error
will not compile successfully
none of these
Which statement is false?
The brackets used to enclose the subscript of an array are not an operator in C.
To refer to a particular element in an array, we specify the name of the array and the position number of the element in the array.
The position number within an array is more formally called a subscript.
“Array element seven” and the “seventh element of an array” do not mean the same thing. This is a frequent source of off-by-one errors.
Choose a correct array statement.
An array size can not changed once it is created.
Array element value can be changed any number of times
To access Nth element of an array students, use students[n-1] as the starting index is 0.
All the above
(a)
8
2
9
Error
No output
0
1
5
garbage value
Error
1,2,3
4,5,6
5,7,9
Error
30 30 garbage value
30 30 30
30 20 garbage value
30 60 40
Garbage value
0
1
Compiler dependent
(a)
(a)
(a)
How to initialize an array in C? tick all the correct statement.
int arr[3] = {1,2,3}
int arr(3) = {1,2,3};
int arr(3) = (1,2,3);
int arr[3] = (1,2,3);
int arr[3] = {0}
What is the proper declaration for an array that has 2 rows and 3 columns?
type arr[2][2];
arr[2][3] type;
type arr[2][3];
type arr[4][3];
How can I store the value 10 into the second row, first column of my array that I have declared as int numbers[10][10]?
int numbers[1][2] = 10;
numbers[1][2] = 10;
numbers[2][3] = 10;
numbers[1][0] = 10
(a)
Compilation Error
14
13
Garbage Value
321004
3210
01234
400123
432100
1 2 3 4 5 5
1 2 3 4 5 0
1 2 3 4 5 Garbage value
Error
int A[5][4];
What will be the size of above array element ?
(a)
int A[2][2][2];
What will be the size of above array element ?
(a)
Pick all correct statements.
int A[][]={1,2,3,4};
int A[2][]={1,2,3,4};
int A[][2]={1,2,3,4};
int A[2][2]={1,2,3,4};
if two strings are identical then function strcmp() returns
0
-1
true
none of these
what will be the output of the program?
#include <stdio.h>
#include<string .h>
void main()
{
char str1[20]="Hello",str2="world";
strcat(str1,str2);
puts(str1);
return 0;
}
Hello
world
Helloworld
none of the above
str1="6/4";
printf("str1");
6/4
str1
None
Which of the following function is more appropriate for reading in a multi-word string?
scanf()
printf()
puts()
gets()
int main()
{
char str[25];
scanf("%s", str);
printf("%s",str);
return 0;
}
//input: South Africa
South
South Africa
S
Compiler error
What is the output of C program with strings.?
int main()
{
char str1[]="SMART";
char str2[10];
str2 = str1;
printf("%s",str2);
return 0;
}
SMART
SMART followed by 5 spaces
SMART followed by 4 spaces
can not assign one string to another
What will the output of the following program?
#include <stdio.h>
int main()
{
char str1[] = "College";
char str2[] = "University";
strcpy(str1, str2);
printf("%s", str1);
}
College
University
College University
University College
