This section on C++ quiz on “C Standard Library”. One shall practice these online quizzes 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++ quiz comes with detailed explanation of the answers which helps in better understanding of C++ concepts.
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) iterators
Answer: b
Clarification: 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
Answer: a
Clarification: 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
Answer: d
Clarification: The floating point number composed of four elements. They are sign, Base, Significand and Exponent.
4. What will be the output of the following C++ code?
-
#include
-
#include
-
int main ()
-
{
-
char s[] = "365.24 29.53";
-
char* p;
-
double d1, d2;
-
d1 = strtod (s, &p);
-
d2 = strtod (p, NULL);
-
printf ("%.2fn", d1/d2);
-
return 0;
-
}
a) 12
b) 12.37
c) 13
d) 15
Answer: b
Clarification: 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 will be the output of the following C++ code?
-
#include
-
#include
-
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 ("%dn",*p);
-
return 0;
-
}
a) 10
b) 20
c) 40
d) 30
Answer: c
Clarification: In this program, We are searching for the element and then we are printing it.
Output:
$ g++ cinc1.cpp
$ a.out
40
6. What will be the output of the following C++ code?
-
#include
-
#include
-
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) 4325
Answer: c
Clarification: 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?
-
#include
-
#include
-
int main ()
-
{
-
printf ("The value of -3.1416 is %lfn", fabs (-3.1416));
-
return 0;
-
}
a) 3.1416
b) -3.1416
c) -3.141600
d) 3.141600
Answer: d
Clarification: 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?
-
#include
-
#include
-
int main ()
-
{
-
div_t divresult;
-
-
divresult = div (38, 5);
-
printf ("%dn", divresult.rem);
-
return 0;
-
}
a) 7
b) 3
c) 4
d) 9
Answer: b
Clarification: 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
Answer: c
Clarification: 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 can be written as .
10. Pick out the correct syntax of the header file that can be used with C++.
a) #include
b) #include
c) Both #include & #include
d) #include
Answer: b
Clarification: The C header file that is ending with h can only be used in C++.