Font size
WorksheetsQuiz-6-Strings-sec-G
Total questions: 93
Worksheet time: 1hrs 13mins
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
What is the Format specifier used to print a String or Character array in C Printf or Scanf function.?
%d
%f
%s
%c
What is the output?
int main()
{
char str[]={'B','M','E','\0'};
printf("%s",str);
return 0;
}
BME
BME with garbage value at the end
BME\0
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
int main()
{
char str[25];
scanf("%s", str);
printf("%s",str);
return 0;
}
//input: South Africa
South
South Africa
S
Compiler error
How do you accept a Multi Word Input in C Language.?
scanf()
gets()
getc()
finds()
Any function working with String knowns the String has ended when it encounters
null character
Empty space
"\1"
pointer
What is the output of C Program with Strings.?
int main()
{
char ary[]="Discovery Channel";
printf("%s",ary);
return 0;
}
D
Discovery Channel
Discovery
Compiler error
Size of the array need not be specified, when
Initialization is a part of definition
It is a formal parameter
It is a declaration
All of the above
An array Index starts with.?
-1
0
1
2
str1="6/4";
printf("str1");
6/4
str1
None
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
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
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 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
Given the code, what is in values[2][1] ?
7.9
9.2
7.3
0.5
Each piece of data in an array is BEST described as a what?
Integer and string
Item
Element
Elephant
Which BEST describes an array?
A data structure - Stores a collection of values under one name
A data collection - Stores a structure of values under one name
A list - Stores a list of numbers
A list - Stores a list of strings
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 will be the output of the C program?
#include<stdio.h>
int main()
{
int 1_one = 25;
printf("%d",1_one);
return 0;
}
2
25
1
Compilation Error
The fastest data access is provided using __________
Caches
DRAM’s
SRAM’s
Registers
What is the output of the following printf
printf("%d",34+24/12%3*5/2-4);
35
-2
34
38
What is the output of the following code:
#include<stdio.h>
void main()
{
int a=10,b=80,c=45;
printf("%d",a<b>c);
}
0
1
10
Error
What is the output of the following code:
#include<stdio.h>
void main()
{
int a=10,b=-5;
printf("%d",a&&b);
}
1
0
Error
10
-5
What is the output of the following printf
int a=9;
printf("%d",~a);
10
-10
6
-9
What is the output of the following printf
int a=-11;
printf("%d",!a);
0
1
12
10
What is the output of the following printf:
int a=6,b=8;
printf("%d",a^b);
14
0
6
8
What is the output of the following printf:
int a=10;
b=++a;
printf("%d,%d",a,b);
11,11
10,11
11,10
10,10
What is the value of printf:
printf("%d",sizeof(double));
8
10
4
6
Which of the following ternary operator is correct to findout biggest of 3 numbers:
c>a?(c>b?c:b):(a>b?a:b)
b<a?(a>c?a:c):(b<c?b:c)
c<b?(b<a?b:a):(c<a?c:a)
a<b?(b>c?b:c):(a<c?c:a)
What is the return value of the following statement if it is placed in C program? strcmp(“ABC”,”ABC”);
33
-1
1
0
Which built in function is used to convert string to lowercase
strlen()
strlwr()
strcmp()
strrev()
Which is not a built in function
string()
strlen()
strcat()
strrev()
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
Which of the following function is more appropriate for reading in a multi-word string?
scanf()
gets()
printf()
puts()
The library function used to copy a string to another is
strncpy()
strcmp()
strcpy()
strchr()
String is initialized with datatype
float
char
int
double
Strcat() function adds null character
Only if there is space
Always
Depends on the standard
Depends on the compiler
What will be the output of the below program
#include <stdio.h>
#include <string.h>
int main( )
{
char source[ ] = " fresh2refresh" ;
char target[ ]= " C tutorial" ;
strcat ( target, source ) ;
printf ( "\nTarget string after strcat( ) = %s", target ) ;
}
Target string after strcat( ) = fresh2refresh
Target string after strcat( ) = C tutorial
Target string after strcat( ) =
Target string after strcat( ) = C tutorial fresh2refresh
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
#include <stdio.h>
#include <string.h>
int main()
{
char s1[30] = "string 1";
char s2[30] = "string 2: Am using strncpy now";
strncpy(s1,s2, 12);
printf("String s1 is: %s", s1);
return 0;
}
String s1 is: string 2: Am
String s1 is: string 2: A
String s1 is: string 2:
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 is the output of the below program
#include <stdio.h>
#include <ctype.h>
void strupr(char s[])
{
int i = 0;
while(s[i] != '\0')
{
printf("%c",toupper(s[i]));
i++;
}
printf("\n");
}
int main()
{
strupr("Hello Shivamogga");
return 0;
}
Hello Shivamogga
HELLO Shivamogga
Error
HELLO SHIVAMOGGA
What is the output of the below program
#include <stdio.h>
int main()
{
char str[ ] = "Hello";
int i;
for( i=2; i<4; i++)
{
printf("%c", str[i]);
}
return 0;
}
He
ll
el
lo
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
What is the output of the below program
#include <stdio.h>
int main()
{
char str[]="JNNCE", ch='N';
int i, frequency = 0;
for(i = 0; str[i] != '\0'; ++i)
{
if(ch == str[i])
++frequency;
}
printf("Frequency of %c = %d", ch, frequency);
return 0;
}
Frequency of N = 0
Frequency of N = -1
Frequency of N = 2
None of the above
The library function used to calculate the length of the string is
strstr()
strrev()
strlen()
strcat()
Given the code, what is in values[2][1] ?
7.9
9.2
7.3
0.5
Given the code, what is the value of things.length ?
4
3
12
7
Given the following:
double [][] stuff ;
Which of the following statements constructs an array with 5 rows of 7 columns each and assign its reference to stuff ?
stuff = new stuff[5][7] ;
stuff = new double[5][7] ;
new stuff = double[5][7] ;
stuff = double new[5][7] ;
Given the code, which of the following fragments prints out every element of items?
Each piece of data in an array is BEST described as a what?
Integer and string
Item
Element
Elephant
Which BEST describes an array?
A data structure - Stores a collection of values under one name
A data collection - Stores a structure of values under one name
A list - Stores a list of numbers
A list - Stores a list of strings
Why are arrays useful?
It saves storage space storing under one name
You can store integers and strings together
You can store thing related on different topics
You may have lots of related data that you don't want to store separately
Which of the following statements correctly declares a two-dimensional integer array?
int Matrix[ ] = new int[5,4];
int Matrix[ ]; Matrix = new int[5,4];
int Matrix[ ][ ] = new int[5][4];
int Matrix[ ][ ] = int[5][4];
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
An array elements are always stored in ________ memory locations.
sequential
Random
Sequential and Random
None of the above
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 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
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 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
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
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.
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 is the output of C Program with Strings.?
int main()
{
char str[]={'B','M','E'};
printf("%s",str);
return 0;
}
BME
B
E
BME with garbage value at the end
What is the output?
int main()
{
char str[]={'B','M','E','\0'};
printf("%s",str);
return 0;
}
BME
BME with garbage value at the end
BME\0
error
How to convert the following character array into string?
char ary[]={'B','M','E'};
ary[3]=0;
ary[3]='\0';
declaration as: char ary[]={'B','M','E','\0'};
All of the given options
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 is the output of the following program?
int main()
{
char str1[]="SMART";
str1="Smart and Brilliant";
printf("%s",str1);
return 0;
}
SMART
Smart and Brilliant
SMART and Brilliant
Compile time Error
What is the correct syntax for initializing a string in C?
char str[10] = {'H', 'e', 'l', 'l', 'o', '\0'};
char str[10] = "Hello";
char str[] = {'H', 'e', 'l', 'l', 'o', '\0'};
char str[] = "Hello";
Comment on the following pointer declaration?
int *p, x;
p is a pointer to integer, x is not
p and x, both are pointers to integer
p is pointer to integer, x may or may not be
p and x both are not pointers to integer
If we pass an array as an argument to a function, what actually gets passed?
Value of elements in array
First element of the array
Base address of the array i.e., the address of the first element
Address of the last element of array
what is the output of the following program?
5
15
20
0
What will be the output of the following code snippet?
30
29
36
34
What will be the output of the following code snippet?
18
20
17
25
