C++ Programming Questions and Answers – C Standard Library

This section on C++ Multiple Choice Questions focuses on “C Standard Library”. One shall practice these questions 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 C++ questions comes with detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of C++ Questions & Answers focuses on “C Standard Library” along with answers, explanations and/or solutions:

1. Where are standard C libraries defined in C++?
a) Container
b) std namespace
c) list
d) iterators
View Answer

Answer: b
Explanation: Every element of the c library is defined within the std namespace.

2. Which of the following have their changes in their declaration related to constness of parameter?
a) strchr
b) string
c) memory
d) strcybrk
View Answer

Answer: a
Explanation: These are the items which will have their change in declaration related to constness of parameter. They are strchr, strpbrk, strrchr, strstr, memchr.

3. How many elements does a floating point number is composed of?
a) 1
b) 2
c) 3
d) 4
View Answer

Answer: d
Explanation: The floating point number composed of four elements. They are sign, Base, Significand and Exponent.
advertisement
advertisement

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

  1.     #include <stdio.h>    
  2.     #include <stdlib.h>
  3.     int main ()
  4.     {
  5.         char s[] = "365.24 29.53";
  6.         char* p;
  7.         double d1, d2;
  8.         d1 = strtod (s, &p);
  9.         d2 = strtod (p, NULL);
  10.         printf ("%.2f\n", d1/d2);
  11.         return 0;
  12.     }

a) 12
b) 12.37
c) 13
d) 15
View Answer

Answer: b
Explanation: In this program, We are calculating the double value by using the floating point number and we are using the function strtod.
Output:

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
$ g++ cinc.cpp
$ a.out
12.37

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

advertisement
  1.     #include <stdio.h>
  2.     #include <stdlib.h>
  3.     int compareints (const void * a, const void * b)
  4.     {
  5.         return ( *(int*)a - *(int*)b );
  6.     }
  7.     int values[] = { 50, 20, 60, 40, 10, 30 };
  8.     int main ()
  9.     {
  10.         int * p;
  11.         int key = 40;
  12.         qsort(values, 6, sizeof (int), compareints);
  13.         p = (int*) bsearch (&key, values, 6, sizeof (int), compareints);
  14.         if (p != NULL)
  15.         printf ("%d\n",*p);
  16.         return 0;
  17.     }

a) 10
b) 20
c) 40
d) 30
View Answer

Answer: c
Explanation: In this program, We are searching for the element and then we are printing it.
Output:

advertisement
$ g++ cinc1.cpp
$ a.out
40

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

  1.     #include <stdio.h>    
  2.     #include <stdlib.h>   
  3.     int main ()
  4.     {
  5.         int n, m;
  6.         n = abs(23);
  7.         m = abs(-11);
  8.         printf ("%d", n);
  9.         printf ("%d", m);
  10.         return 0;
  11.     }

a) 23-11
b) 1123
c) 2311
d) 4325
View Answer

Answer: c
Explanation: In this program, We are finding the absolute value of the n.
Output:

$ g++ cinc2.cpp
$ a.out
2311

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

  1.     #include <stdio.h>
  2.     #include <math.h>
  3.     int main ()
  4.     {
  5.         printf ("The value of -3.1416 is %lf\n", fabs (-3.1416));
  6.         return 0;
  7.     }

a) 3.1416
b) -3.1416
c) -3.141600
d) 3.141600
View Answer

Answer: d
Explanation: In this program, We are finding the absolute value of a floating point value.
Output:

$ g++ cinc3.cpp
$ a.out
3.141600

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

  1.     #include <stdio.h>
  2.     #include <stdlib.h>
  3.     int main ()
  4.     {
  5.         div_t divresult;
  6.  
  7.         divresult = div (38, 5);
  8.         printf ("%d\n", divresult.rem);
  9.         return 0;
  10.     }

a) 7
b) 3
c) 4
d) 9
View Answer

Answer: b
Explanation: In this program, We are finding the remainder of a number by using div function.
Output:

$ g++ cinc4.cpp
$ a.out
3

9. How does the limits.h header file can be represented in C++?
a) limits
b) limit
c) climits
d) dlimits
View Answer

Answer: c
Explanation: Any standard library of C can be written in C++ by using ‘c’ in front of header file name and omitting the ‘.h’. for example <limits.h> can be written as <climits>.

10. Pick out the correct syntax of the header file that can be used with C++.
a) #include <float>
b) #include <float.h>
c) Both #include <float> & #include <float.h>
d) #include <flot.h>
View Answer

Answer: b
Explanation: The C header file that is ending with h can only be used in C++.

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.

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.