This section on C++ MCQs (multiple choice questions) on “Locale”. One shall practice these MCQs to improve their C++ programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our multiple choice questions come with detailed explanation of the answers which helps in better understanding of C++ concepts.
Here is a listing of C multiple choice questions on “Locale” along with answers, explanations and/or solutions:
1. What is the main feature of locale in C++?
a) Sustainability
b) Portability
c) Reliability
d) Sustainability & Reliability
Answer: b
Clarification: A locale is a set of features that are culture-specific, which can be used by programs to be more portable internationally.
2. Which objects information is loaded in locale object?
a) facet object
b) instead object
c) Both facet & instead object
d) secant object
Answer: a
Clarification: A locale object contains information about which facet objects constitute a locale, and is each one of these facet objects that implements specific features as member functions.
3. How many categories are available in facets?
a) 4
b) 5
c) 6
d) 3
Answer: c
Clarification: There are 6 categories of facet in c++. They are collate, ctype, monetary, numeric, time and messages.
4. What will be the output of the following C++ code?
-
#include
-
#include
-
int main ()
-
{
-
int i = 0;
-
char str[] = "Steve Jobsn";
-
char c;
-
while (str[i])
-
{
-
c = str[i];
-
if (islower(c))
-
c = toupper(c);
-
putchar (c);
-
i++;
-
}
-
return 0;
-
}
a) Steve jobs
b) STEVE JOBS
c) Steve
d) JOBS
Answer: b
Clarification: In this program, We have converted the lower case letters to uppercase letters by using toupper function.
Output:
$ g++ loc.cpp
$ a.out
STEVE JOBS
5. What will be the output of the following C++ code?
-
#include
-
#include
-
int main ()
-
{
-
int i = 0;
-
char str[] = "C";
-
while (str[i])
-
{
-
if (isalpha(str[i]))
-
printf ("alphabetic");
-
else
-
printf ("not alphabetic");
-
i++;
-
}
-
return 0;
-
}
a) alphabetic
b) not alphabetic
c) Error
d) alphabeticnot alphabetic
Answer: a
Clarification: In this program, We are checking whether the character is alphabetic or not alphabetic by using the function isalpha.
Output:
$ g++ loc1.cpp
$ a.out
alphabetic
6. What will be the output of the following C++ code?
-
#include
-
#include
-
int main ()
-
{
-
int i;
-
char str[] = "jobs...";
-
i = 0;
-
while ( isalnum(str[i] ))
-
i++;
-
printf (" %dn",i);
-
return 0;
-
}
a) 1
b) 2
c) 3
d) 4
Answer: d
Clarification: In this program, We are counting the number of alphanumeric values by using the function isalnum.
Output:
7. What will be the output of the following C++ code?
-
#include
-
#include
-
int main ()
-
{
-
int i = 0;
-
int cx = 0;
-
char str[] = "Hello, welcome!";
-
while (str[i])
-
{
-
if (ispunct(str[i])) cx++;
-
i++;
-
}
-
printf ("%dn", cx);
-
return 0;
-
}
a) 1
b) 2
c) 3
d) 4
Answer: b
Clarification: In this program, We are counting the number of special characters in the program by using the function ispunct.
Output:
8. What will be the output of the following C++ code?
-
#include
-
#include
-
#include
-
int main ()
-
{
-
char str[] = "ffff";
-
long int number;
-
if (isxdigit(str[0]))
-
{
-
number = strtol (str, NULL, 16);
-
printf ("%ldn", number);
-
}
-
return 0;
-
}
a) 64345
b) 21312
c) 65535
d) Error
Answer: c
Clarification: In this program, We are converting the hexadecimal number to decimal number.
Output:
$ g++ loc4.cpp
$ a.out
65535
9. What kind of locale does every program is having in C++?
a) local locale
b) global locale
c) temp locale
d) set locale
Answer: b
Clarification: Every program has a single locale object which is its global locale.
10. What will the monetary facet will do?
a) Handle formatting and parsing of monetary values
b) Handle formatting and parsing of character values
c) Parsing of character values
d) Deleting a character values
Answer: a
Clarification: Monetary facet will handle formatting and parsing of monetary values.