Font size
WorksheetsIP Unit 3
Total questions: 54
Worksheet time: 28mins
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() {
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
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}
Arrays are structures that hold multiple variables of the _____________ data type
int data type
char data type
same data type
different data type
What is the index number of the last element of an array with 29 elements?
29
28
0
Programmer-defined
Which of the following is a two-dimensional array?
array anarray[20][20];
int anarray[20][20];
int array[20, 20];
char array[20];
What is an array in C programming?
A method for sorting data
A type of function
A collection of different data types
A sequential collection of similar data items
How is a single-dimensional array declared in C?
size array_name[datatype];
datatype array_name[size];
array_name[size] datatype;
datatype[size] array_name;
What is the index range for an array of size n?
0 to n
1 to n-1
0 to n-1
1 to n
What does the scanf() function do in C?
Declares variables
Prints output to the screen
Allocates memory for arrays
Reads input from the keyboard
What is the output of printf("%d", a[0]); if a is an array of integers?
The first element of the array
The size of the array
The address of the array
The last element of the array
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
To access an array element, use the array name and the element's ___________.
data type
subscript
value
name
In an array, every element has the same
data type
memory location
subscript
all of the above
Given the following declaration, where is the value 77 stored in the scores array?
int scores[] = {83, 62, 77, 97, 86}
scores[0]
scores[1]
scores[2]
scores[3]
Before using an array its type and dimension must be declared?
True
False
In general, the index of the first element in an array is __________
0
-1
2
1
What is meaning of following
declaration ?
int arr[20];
Array of size 20 that can have integer address
Array of Size 20
Integer Array of size 20
None of these
what will be the output of the following code snippet
#include <stdio.h>
int main()
{
int a = 3, b = 5;
int t = a;
a = b;
b = t;
printf("%d %d", a, b);
return 0;
}
3 5
3 3
5 5
5 3
What is the output of the following code snippet?
#include <stdio.h>
int main() {
int a[] = {1, 2, 3, 4};
int sum = 0;
for(int i = 0; i < 4; i++) {
sum += a[i];
}
printf("%d", sum);
return 0;
}
1
4
20
10
Arrays are structures that hold multiple variables of the _____________ data type
int data type
char data type
same data type
different data type
Array locations are considered to be
contiguous
adjacent
randon
dynamic
An array item is referenced by its
index
value
variable
type
Which statement allows the user to input an element into an array?
scanf("%d', &num);
scanf("%d', &num[0]);
num[0] = 20;
int num[] = {0};
An array does not need a defined size.
True
False
which string library function allows you to compare two words?
strlen
strcmp
strrev
strcpy
if two strings are identical then function strcmp() returns
0
-1
true
none of these
What will be the output of the following program?
#include <stdio.h>
int main()
{
char str1[] = "Sona BME";
char str2[] = "Sona BME";
printf("%d" ,(strcmp(str1, str2)));
}
0
1
-1
error
What will be the output of the following program?
#include <stdio.h>
int main()
{
char str1[] = "Salem";
char str2[] = "Bangalore";
printf("%d" ,(strcmp(str1, str2)));
}
0
-1
1
Compile time Error
What will the output of the following program?
#include <stdio.h>
int main()
{
char str1[] = " Sona College";
char str2[] = "Sona University";
strcpy(str1, str2);
printf("%s", str2);
}
Sona College
Sona University
Sona College Sona University
Sona University Sona College
What will be thee output of the following program?
#include <stdio.h>
int main()
{
char str[] = " Have a Good Day ! ";
printf("%d", strlen(str));
}
20
13
19
18
What will be the output of the following C code?
#include <stdio.h>
int main()
{
char str1[] = "BioMedical ";
char str2[] = "Engineering";
strcat(str1, str2);
printf("%s ", str1);
}
BioMedical
BioMedical Engineering
BioEngineering
Engineering
Choose a correct statement about C String
Character array, ary is a string
ary has no Null character at the end
String size is not mentioned
String can not contain special characters
What is the Format specifier used to print a String or Character array in C Printf or Scanf function.?
%d
%f
%s
%c
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
str1="6/4";
printf("str1");
6/4
str1
None
What will be the output of the following program?
#include <stdio.h>
int main()
{
char str1[] = "Australia";
char str2[] = "India";
printf("%d" ,(strcmp(str1, str2)));
}
0
-1
1
run time error
Which of the following is true about strcat function?
Strcat() function adds null character
Only if there is space
Always
Depends on the standard
Depends on the compiler
How would you get the value "6" out of the following array?
a [0][3]
a [1][3]
c) a[0][2]
d) a[2][0]
e) a[3][1]
What would the statement a[1].length return?
3
4
2
1
What will be thee output of the following program?
#include <stdio.h>
int main()
{
char str[] = " Have a Good Day ! ";
printf("%d", strlen(str));
}
20
13
19
18
Which is not a built in function
string()
strlen()
strcat()
strcmp()
String is initialized with datatype
float
char
int
double
The "\n" character does which of the following operations?
Double line spacing
Character deletion
Character backspace
Places cursor on the next line
Which of the following is the correct operator to compare two variables?
equal
=
:=
==
Every variable must be -------------- before it is used.
executed
defined
declared
identified
________to be included to use mathematical functions sqrt()
#include<conio.h>
#include<string.h>
#include<math.h>
#include<stdio.h>
_______________to be included to use standard I/O functions : prinf(),scanf()
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
