22. What is the correct syntax to define a union in C++?
23. What is the output of the following code: struct Book { char title[50]; int pages; }; Book b; cout << sizeof(b); in C++?
24. What is the output of the following code: union Number { int x; float y; }; Number n; n.x = 10; cout << n.y; in C++?
25. What is a dangling pointer in C++?
26. The declaration of the structure is also called as?
27. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
struct sec
{
int a;
char b;
};
int main()
{
struct sec s ={25,50};
struct sec *ps =(struct sec *)&s;
cout << ps->a << ps->b;
return 0;
}
#include <iostream>
using namespace std;
struct sec
{
int a;
char b;
};
int main()
{
struct sec s ={25,50};
struct sec *ps =(struct sec *)&s;
cout << ps->a << ps->b;
return 0;
}
28. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
struct Time
{
int hours;
int minutes;
int seconds;
};
int toSeconds(Time now);
int main()
{
Time t;
t.hours = 5;
t.minutes = 30;
t.seconds = 45;
cout << "Total seconds: " << toSeconds(t) << endl;
return 0;
}
int toSeconds(Time now)
{
return 3600 * now.hours + 60 * now.minutes + now.seconds;
}
#include <iostream>
using namespace std;
struct Time
{
int hours;
int minutes;
int seconds;
};
int toSeconds(Time now);
int main()
{
Time t;
t.hours = 5;
t.minutes = 30;
t.seconds = 45;
cout << "Total seconds: " << toSeconds(t) << endl;
return 0;
}
int toSeconds(Time now)
{
return 3600 * now.hours + 60 * now.minutes + now.seconds;
}
29. What will be the output of the following C++ code?
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
struct student
{
int num;
char name[25];
};
student stu;
stu.num = 123;
strcpy(stu.name, "John");
cout << stu.num << endl;
cout << stu.name << endl;
return 0;
}
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
struct student
{
int num;
char name[25];
};
student stu;
stu.num = 123;
strcpy(stu.name, "John");
cout << stu.num << endl;
cout << stu.name << endl;
return 0;
}