Structures C++ MCQ

Errorlogger
0
1. The data elements in structure are also known as what?
a) objects
b) members
c) datas
d) none of the mentioned




2. What will be used when terminating a structure?
a) :
b) }
c) ;
d) ;;




3. What will happen when the structure is declared?
a) it will not allocate any memory
b) it will allocate the memory
c) it will be declared and initialized
d) none of the mentioned




4. The declaration of structure is also called as?
a) sructure creator
b) structure signifier
c) structure specifier
d) none of the mentioned




5. What is the output of this program?
  1.     #include <iostream>
  2.     #include <string.h>
  3.     using namespace std;
  4.     int main()
  5.     {
  6.         struct student {
  7.             int num;
  8.             char name[25];
  9.         };
  10.         student stu;
  11.         stu.num = 123;
  12.         strcpy(stu.name, "Vansh");
  13.         cout << stu.num << endl;
  14.         cout << stu.name << endl;
  15.         return 0;
  16.     }
a) 123
    Vansh
b) Vansh
     Vansh
c) compile time error
d) none of the mentioned




6. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     struct Time {
  4.         int hours;
  5.         int minutes;
  6.         int seconds;
  7.     };
  8.     int toSeconds(Time now);
  9.     int main()
  10.     {
  11.         Time t;
  12.         t.hours = 5;
  13.         t.minutes = 30;
  14.         t.seconds = 45;
  15.         cout << "Total seconds: " << toSeconds(t) << endl;
  16.         return 0;
  17.     }
  18.     int toSeconds(Time now)
  19.     {
  20.         return 3600 * now.hours + 60 * now.minutes + now.seconds;
  21.     }
a) 19845
b) 20000
c) 15000
d) 19844




7. What will be the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         struct ShoeType {
  6.             char style;
  7.            double price;
  8.         };
  9.          ShoeType shoe1, shoe2;
  10.          shoe1.style = 'Adidas';
  11.          shoe1.price = 9.99;
  12.          cout << shoe1.style << " $ "<< shoe1.price;
  13.          shoe2 = shoe1;
  14.          shoe2.price = shoe2.price / 9;
  15.          cout << shoe2.style << " $ "<< shoe2.price;
  16.          return 0;
  17.     }
a) Adidas $ 9.99
    Adidas $ 1.11
b) Adidas $ 9.99
    Adidas $ 9.11
c) Adidas $ 9.99
    Adidas $ 11.11
d) none of the mentioned




8. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     struct sec {
  4.         int a;
  5.         char b;
  6.     };
  7.     int main()
  8.     {
  9.         struct sec s ={25,50};
  10.         struct sec *ps =(struct sec *)&s;
  11.         cout << ps->a << ps->b;
  12.         return 0;
  13.     }
a) 252
b) 253
c) 254
d) 262




9. Which of the following is a properly defined structure?
a) struct {int a;}
b) struct a_struct {int a;}
c) struct a_struct int a;
d) struct a_struct {int a;};




10. Which of the following accesses a variable in structure *b?
a) b->var;
b) b.var;
c) b-var;
d) b>var;



Tags

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(30)

Our website uses cookies to enhance your experience. Check Now
Accept !