Data Structures
- Which of the following accesses a variable in structure *p?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Because in a structure pointer, the data element is declared as above only.
- Which of the following is a properly defined structure?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
The p_struct is declared as structure name and its data element is p.
- What is the output of this program?
#include
using namespace std;
struct second
{
int p;
char q;
};
int main()
{
struct second sec ={30,210};
struct second *ps =(struct second *)&sec;
cout << ps->p <<" "<< ps->q;
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
30 F
- What will be the output of this program?
#include
using namespace std;
int main()
{
struct MansWear
{
string Brand;
double price;
};
MansWear MansWear1, MansWear2;
MansWear1.Brand = "Peter England";
MansWear1.price = 999.99;
cout << MansWear1.Brand << " $ "<MansWear2 = MansWear1;
MansWear2.price = MansWear2.price / 10;
cout << MansWear1.Brand << " $ "<< MansWear2.price;
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
We copied the value of MansWear1 into MansWear2 and divide the MansWear2 value by 10, So this is the output.
Peter England $ 999.99
Peter England $ 99.999
- What is the output of this program?
#include
using namespace std;
struct T
{
int H;
int M;
int S;
};
int Seconds(T now);
int main()
{
T t;
t.H = 6;
t.M = 3;
t.S = 15;
cout << "Total seconds: " << Seconds(t) << endl;
return 0;
}
int Seconds(T now)
{
return 3600 * now.H + 60 * now.M + now.S;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
In this program, we are just converting the given hours and minutes into seconds.