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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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 <stdio.h>
#include <ctype.h>
int main ()
{
int i = 0;
char str[] = "Steve Jobs\n";
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
View Answer
Explanation: 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 <stdio.h>
#include <ctype.h>
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
View Answer
Explanation: 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 <stdio.h>
#include <ctype.h>
int main ()
{
int i;
char str[] = "jobs...";
i = 0;
while ( isalnum(str[i] ))
i++;
printf (" %d\n",i);
return 0;
}
a) 1
b) 2
c) 3
d) 4
View Answer
Explanation: In this program, We are counting the number of alphanumeric values by using the function isalnum.
Output:
$ g++ loc2.cpp $ a.out 4
7. What will be the output of the following C++ code?
#include <stdio.h>
#include <ctype.h>
int main ()
{
int i = 0;
int cx = 0;
char str[] = "Hello, welcome!";
while (str[i])
{
if (ispunct(str[i])) cx++;
i++;
}
printf ("%d\n", cx);
return 0;
}
a) 1
b) 2
c) 3
d) 4
View Answer
Explanation: In this program, We are counting the number of special characters in the program by using the function ispunct.
Output:
$ g++ loc3.cpp $ a.out 2
8. What will be the output of the following C++ code?
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main ()
{
char str[] = "ffff";
long int number;
if (isxdigit(str[0]))
{
number = strtol (str, NULL, 16);
printf ("%ld\n", number);
}
return 0;
}
a) 64345
b) 21312
c) 65535
d) Error
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: Monetary facet will handle formatting and parsing of monetary values.
Sanfoundry Global Education & Learning Series – C++ Programming Language.
To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Apply for Computer Science Internship
- Practice Computer Science MCQs
- Check C++ Books
- Apply for Information Technology Internship
- Check Computer Science Books