1 Crore+ students have signed up on EduRev. Have you? Download the App |
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;
}
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;
}
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;
}
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
struct ShoeType
{
string style;
double price;
};
ShoeType shoe1, shoe2;
shoe1.style = "Adidas";
shoe1.price = 9.99;
cout << shoe1.style << " $ "<< shoe1.price;
shoe2 = shoe1;
shoe2.price = shoe2.price / 9;
cout << shoe2.style << " $ "<< shoe2.price;
return 0;
}