NEW
Font size
WorksheetsArrays and Strings in C
Total questions: 32
Worksheet time: 16mins
Array can be considered as set of elements stored in consecutive memory locations but having __________.
Same data type
Different data type
Same scope
None of these
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
1 2 3 4 5 5
1 2 3 4 5 0
1 2 3 4 5 Garbage value
Error
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
What is right way to Initialize array?
int num[6] = { 2, 4, 12, 5, 45, 5 };
int n{} = { 2, 4, 12, 5, 45, 5 };
int n{6} = { 2, 4, 12 };
int n(6) = { 2, 4, 12, 5, 45, 5 };
An array elements are always stored in ________ memory locations.
sequential
Random
Sequential and Random
None of the above
what will be printed after Execution of the following program
void main()
{
int a[5]={11,13,56,20,5};
printf("%d",a[2]);
}
garbage value
13
56
20
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 a String in C Language.?
String is a new Data Type in C
String is an array of Characters with null character as the last element of array.
String is an array of Characters with null character as the first element of array
String is an array of Integers with 0 as the last element of array
An array Index starts with.?
-1
0
1
2
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 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 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
Which is not a built in function
string()
strlen()
strcat()
strcmp()
String is an array of characters with …….. character as the last element of array.
Null
Empty
0
1
What is the format specifier used to print or read a character in an array in Printf or Scanf function?
%C
%f
%w
%c
String is initialized with datatype
float
char
int
double
What is the output of this program?
#include <stdio.h>
int main()
{
char str[] = "hello, world";
printf("%d", strlen(str));
}
Compilation error
10
13
12
What is the output of
#include <stdio.h>
int main()
{
char str[8]="IncludeHelp";
printf("%s",str);
return 0;
}
IncludeHelp
IncludeH
Error
No Output
What is the output of this
#include <stdio.h>
#include <string.h>
int main()
{
char s1[10] = "Hello";
char s2[10] = "World";
strncat(s1,s2, 3);
printf("Concatenation using strncat: %s", s1);
return 0;
}
Concatenation using strncat: Hel
Concatenation using strncat: HelloWorld
Concatenation using strncat: HelloWor
None of the above
What is the output of the below program
#include <stdio.h>
#include <string.h>
int main()
{
char str1[] = "abcd", str2[] = "abcd";
int result;
result = strcmp(str1, str2);
printf("strcmp(str1, str2) = %d\n", result);
return 0;
}
0
1
Invalid
None of the above
What will be the output of the below program
#include <stdio.h>
int main()
{
int a[5]={5,1,15,20,25};
int i,j,m;
i=++a[1];
j=a[1]++;
m=a[i++];
printf("%d,%d,%d",i,j,m);
}
3,2,15
2,3,20
2,1,15
1,2,5
