Here is a listing of C++ quiz 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) None of the mentioned
View Answer
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) none of the mentioned
View Answer
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
Explanation: The floating point number composed of four elements. They are sign, Base, Significand and Exponent.
4. What is the output of this program?
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char s[] = "365.24 29.53";
char* p;
double d1, d2;
d1 = strtod (s, &p);
d2 = strtod (p, NULL);
printf ("%.2f\n", d1/d2);
return 0;
}
a) 12
b) 12.37
c) 13
d) None of the mentioned
View Answer
Explanation: In this program, We are calculating the double value by using the floating point number and we are using the function strtod.
Output:
$ g++ cinc.cpp
$ a.out
12.37
5. What is the output of this program?
#include <stdio.h>
#include <stdlib.h>
int compareints (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int values[] = { 50, 20, 60, 40, 10, 30 };
int main ()
{
int * p;
int key = 40;
qsort(values, 6, sizeof (int), compareints);
p = (int*) bsearch (&key, values, 6, sizeof (int), compareints);
if (p != NULL)
printf ("%d\n",*p);
return 0;
}
a) 10
b) 20
c) 40
d) 30
View Answer
Explanation: In this program, We are searching for the element and then we are printing it.
Output:
$ g++ cinc1.cpp
$ a.out
40
6. What is the output of this program?
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int n, m;
n = abs(23);
m = abs(-11);
printf ("%d", n);
printf ("%d", m);
return 0;
}
a) 23-11
b) 1123
c) 2311
d) None of the mentioned
View Answer
Explanation: In this program, We are finding the absolute value of the n.
Output:
$ g++ cinc2.cpp
$ a.out
2311
7. What is the output of this program?
#include <stdio.h>
#include <math.h>
int main ()
{
printf ("The value of -3.1416 is %lf\n", fabs (-3.1416));
return 0;
}
a) 3.1416
b) -3.1416
c) -3.141600
d) 3.141600
View Answer
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 is the output of this program?
#include <stdio.h>
#include <stdlib.h>
int main ()
{
div_t divresult;
divresult = div (38, 5);
printf ("%d\n", divresult.rem);
return 0;
}
a) 7
b) 3
c) 4
d) None of the mentioned
View Answer
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) none of the mentioned
View Answer
Explanation: None.
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) None of the mentioned
View Answer
Explanation: The C header file that is ending with h can only be used in C++.
Sanfoundry Global Education & Learning Series – C++ Programming Language.
Here’s the list of Best Reference Books in C++ Programming Language.
To practice all features of C++ programming language, here is complete set on 1000+ Multiple Choice Questions and Answers on C++.