C++ Programming Questions and Answers – Locale

This section on C++ MCQs (multiple choice questions) focuses 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
View Answer

Answer: b
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

Answer: a
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

Answer: c
Explanation: There are 6 categories of facet in c++. They are collate, ctype, monetary, numeric, time and messages.
advertisement
advertisement

4. What will be the output of the following C++ code?

  1.     #include <stdio.h> 
  2.     #include <ctype.h>
  3.     int main ()
  4.     {
  5.         int i = 0;
  6.         char str[] = "Steve Jobs\n";
  7.         char c;
  8.         while (str[i])
  9.         {
  10.             c = str[i];
  11.             if (islower(c)) 
  12.                 c = toupper(c);
  13.             putchar (c);
  14.             i++;
  15.         }
  16.         return 0;
  17.     }

a) Steve jobs
b) STEVE JOBS
c) Steve
d) JOBS
View Answer

Answer: b
Explanation: In this program, We have converted the lower case letters to uppercase letters by using toupper function.
Output:

Note: Join free Sanfoundry classes at Telegram or Youtube
$ g++ loc.cpp
$ a.out
STEVE JOBS

5. What will be the output of the following C++ code?

advertisement
  1.     #include <stdio.h> 
  2.     #include <ctype.h>
  3.     int main ()
  4.     {
  5.         int i = 0;
  6.         char str[] = "C";
  7.         while (str[i])
  8.         {
  9.             if (isalpha(str[i])) 
  10.                 printf ("alphabetic");
  11.             else 
  12.                 printf ("not alphabetic");
  13.             i++;
  14.         }
  15.         return 0;
  16.     }

a) alphabetic
b) not alphabetic
c) Error
d) alphabeticnot alphabetic
View Answer

Answer: a
Explanation: In this program, We are checking whether the character is alphabetic or not alphabetic by using the function isalpha.
Output:

advertisement
$ g++ loc1.cpp
$ a.out
alphabetic

6. What will be the output of the following C++ code?

  1.     #include <stdio.h>
  2.     #include <ctype.h>
  3.     int main ()
  4.     {
  5.         int i;
  6.         char str[] = "jobs...";
  7.         i = 0;
  8.         while ( isalnum(str[i] )) 
  9.             i++;
  10.         printf (" %d\n",i);
  11.         return 0;
  12.     }

a) 1
b) 2
c) 3
d) 4
View Answer

Answer: d
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?

  1.     #include <stdio.h>
  2.     #include <ctype.h>
  3.     int main ()
  4.     {
  5.         int i = 0;
  6.         int cx = 0;
  7.         char str[] = "Hello, welcome!";
  8.         while (str[i])
  9.         {
  10.             if (ispunct(str[i])) cx++;
  11.                 i++;
  12.         }    
  13.         printf ("%d\n", cx);
  14.         return 0;
  15.     }

a) 1
b) 2
c) 3
d) 4
View Answer

Answer: b
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?

  1.     #include <stdio.h>
  2.     #include <stdlib.h>
  3.     #include <ctype.h>
  4.     int main ()
  5.     {
  6.         char str[] = "ffff";
  7.         long int number;
  8.         if (isxdigit(str[0]))
  9.         {
  10.             number = strtol (str, NULL, 16);
  11.             printf ("%ld\n", number);
  12.         }
  13.         return 0;
  14.     }

a) 64345
b) 21312
c) 65535
d) Error
View Answer

Answer: c
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

Answer: b
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

Answer: a
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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.