C Plus Plus Miscellaneous - Study Mode
[#796] What will be the output of the following C++ code? #include <iostream>
#include <stdarg.h>
using namespace std
float avg( int Count, ... )
{
va_list Numbers
va_start(Numbers, Count)
int Sum = 0
for (int i = 0
i < Count
++i)
Sum += va_arg(Numbers, int)
va_end(Numbers)
return (Sum/Count)
}
int main()
{
float Average = avg(10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
cout << Average
return 0
}
Correct Answer
(A) 4
[#797] What will be the output of the following C++ code? #include <iostream>
#include <string>
#include <tuple>
using namespace std
int main()
{
tuple <int, char, string> tp
tp = make_tuple(4, '1', "Hello")
cout<<tuple_size<decltype(tp)>::value
return 0
}
Correct Answer
(D) 3
[#798] 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
"
char c
while (str[i])
{
c = str[i]
if (islower(c))
c = toupper(c)
putchar (c)
i++
}
return 0
}
Correct Answer
(B) STEVE JOBS
[#799] What will be the output of the following C++ code? #include <iostream>
#include <memory>
#include <algorithm>
using namespace std
int main ()
{
int numbers[] = {1, 5, 4, 5}
pair <int*, ptrdiff_t> result = get_temporary_buffer<int>(4)
if (result.second > 0)
{
uninitialized_copy (numbers, numbers + result.second, result.first)
sort (result.first, result.first + result.second)
for (int i = 0
i < result.second
i++)
cout << result.first[i] << " "
return_temporary_buffer (result.first)
}
return 0
}
Correct Answer
(C) 1 4 5 5
[#800] What will be the output of the following C++ code? #include <iostream>
using namespace std
struct X
struct Y
{
void f(X*)
}
struct X
{
private:
int i
public:
void initialize()
friend void g(X* , int)
friend void Y :: f(X*)
friend struct Z
friend void h()
}
void X :: initialize()
{
i = 0
}
void g(X* x, int i)
{
x -> i = i
}
void Y :: f(X * x)
{
x -> i = 47
cout << x->i
}
struct Z
{
private:
int j
public:
void initialize()
void g(X* x)
}
void Z::initialize()
{
j = 99
}
void Z::g(X* x)
{
x -> i += j
}
void h()
{
X x
x.i = 100
cout << x.i
}
int main()
{
X x
Z z
z.g(&x)
cout << "Data accessed"
}
Correct Answer
(C) Data accessed