WorksheetsStrings C
Total questions: 82
Worksheet time: 1hrs 4mins
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()
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 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
A string is a ____________ character array.
Null terminated
fully terminated
listed in parenthesis
Guess the output:
void main()
{
char name[10]=“ECE”;
printf(“Name is %s”,name);
}
Error
ECE
Name is ECE
warning
What will be the output of below C code?
printf(“%.5s”,name);
will print all the characters
will print the name
will print the 5 characters
Who is father of C Language?
Bjarne Stroustrup
James A. Gosling
Dennis Ritchie
Dr. E.F. Codd
In which of the following function compiler used to read strings with blank space?
getchar()
getche()
gets()
None of the Above
In the standard library of C programming language, which of the following header file is designed for string operations?
string.h
conio.h
dos.h
stdio.h
Full form of ASCII code is ___________.
American Standard Code for Internet Interconnection
American Standard Code for Internet Interchange
American Standard Code for Information Interchange
American Standard Captcha for Information Interchange
Which of the following Converts lowercase characters of a string to uppercase in C?
strupr()
strdup()
export
Which of the following is not logical operator?
&
&&
||
!
Select the wrong way to get a string from the user which is declared as follows:
char str[50];
scanf("%s",&str)
scanf("%s",str)
gets(str)
All are correct
A string is a ____________ character array.
Null terminated
fully terminated
listed in parenthesis
Guess the output:
void main()
{
char name[10]=“ECE”;
printf(“Name is %s”,name);
}
Error
ECE
Name is ECE
warning
What will be the output of below C code?
printf(“%.5s”,name);
will print all the characters
will print the name
will print the 5 characters
Who is father of C Language?
Bjarne Stroustrup
James A. Gosling
Dennis Ritchie
Dr. E.F. Codd
In which of the following function compiler used to read strings with blank space?
getchar()
getche()
gets()
None of the Above
In the standard library of C programming language, which of the following header file is designed for string operations?
string.h
conio.h
dos.h
stdio.h
Full form of ASCII code is ___________.
American Standard Code for Internet Interconnection
American Standard Code for Internet Interchange
American Standard Code for Information Interchange
American Standard Captcha for Information Interchange
Which of the following Converts lowercase characters of a string to uppercase in C?
strupr()
strdup()
export
Which of the following is not logical operator?
&
&&
||
!
Select the wrong way to get a string from the user which is declared as follows:
char str[50];
scanf("%s",&str)
scanf("%s",str)
gets(str)
All are correct
