logo
  • Home
  • Rank
  • Tests
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Contact

C++ Multiple Choice Questions | MCQs | Quiz

C++ Interview Questions and Answers
Practice C++ questions and answers for interviews, campus placements, online tests, aptitude tests, quizzes and competitive exams.

Get Started

•   Types
•   Booleans
•   Character Types
•   Integer Types
•   Floating Point Types
•   Sizes
•   Void
•   Enumerations
•   Declaration
•   Pointers
•   Arrays
•   Pointers into Arrays
•   Constants
•   References
•   Pointer to Void
•   Structures
•   Operators
•   Statements
•   Comments & Indentation
•   Function Declarations
•   Argument Passing
•   Value Return
•   Overloaded Function
•   Default Arguments
•   Unspecified Arguments
•   Pointer to Function
•   Macros
•   Modularization
•   Namespaces
•   Exceptions
•   Linkage
•   Header Files Usage
•   Classes
•   User Defined Types
•   Objects
•   Operator Functions
•   Complex Number Type
•   Conversion Operators
•   Friends
•   Large Objects
•   Essential Operators
•   Subscripting
•   Function Call
•   Dereferencing
•   Increment & Decrement
•   String Class
•   Derived Classes
•   Abstract Classes
•   Class Hierarchies
•   Abstract Classes
•   Simple String Template
•   Function Templates
•   Policy Usage Template
•   Specialization
•   Derivation & Templates
•   Error Handling
•   Grouping of Exceptions
•   Catching Exceptions
•   Resource Management
•   Exceptions Not Errors
•   Exception Specifications
•   Uncaught Exceptions
•   Exceptions & Efficiency
•   Error Handling Alternatives
•   Standard Exceptions
•   Class Hierarchies
•   Multiple Inheritance
•   Access Control
•   Run Time Type
•   Pointers to Members
•   Free Store
•   Standard Library Design
•   Container Design
•   Vector
•   Sequences
•   Sequence Adapters
•   Associative Containers
•   Almost Containers
•   Defining a New Container
•   Library Algorithms
•   Sequences / Containers
•   Function Objects
•   Nonmodifying Algorithms
•   Modifying Algorithms
•   Stored Sequences
•   Heaps
•   Min and Max
•   Permutations
•   C Style Algorithms
•   Iterators & Sequences
•   Checked Iterators
•   Allocators
•   String Characters
•   Basic String
•   C Standard Library
•   Output Stream
•   Input Stream
•   Formatting
•   File & String Streams
•   Buffering
•   Locale
•   C Input Output
•   Numeric Limits
•   Mathematical Functions
•   Vector Arithmetic
•   Numeric Algorithms
•   Random Numbers

C++ Tests

C++ Tests

Best Reference Books

C++ Books
« Prev Page
Next Page »

C++ Programming Questions and Answers – Structures

Posted on November 13, 2012 by Manish
This section on C++ interview questions and answers focuses on “Structures”. One shall practice these interview questions to improve their C++ programming skills needed for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ interview questions come with the detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of C++ interview questions on “Structures” along with answers, explanations and/or solutions:

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

Answer: b
Explanation: Variables declared inside a class are called as data elements or data members.
advertisement

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

Answer: c
Explanation: While terminating a structure, a semicolon is used to end this up.

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
View Answer

Answer: a
Explanation: While the structure is declared, it will not be initialized, So it will not allocate any memory.

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

Answer: c
Explanation: The structure declaration with open and close braces and with a semicolon is also called structure specifier.

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.         {
  8.             int num;
  9.             char name[25];
  10.         };
  11.         student stu;
  12.         stu.num = 123;
  13.         strcpy(stu.name, "John");
  14.         cout << stu.num << endl;
  15.         cout << stu.name << endl;
  16.         return 0;
  17.     }

a) 123
john
b) john
john
c) compile time error
d) none of the mentioned
View Answer

Answer: a
Explanation: We are copying the value john to the name and then we are printing the values that are in the program.
Output:

advertisement
$ g++ stu.cpp
$ a.out
123
john

6. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     struct Time 
  4.     {
  5.         int hours;
  6.         int minutes;
  7.         int seconds;
  8.     };
  9.     int toSeconds(Time now);
  10.     int main()
  11.     {
  12.         Time t;
  13.         t.hours = 5;
  14.         t.minutes = 30;
  15.         t.seconds = 45;
  16.         cout << "Total seconds: " << toSeconds(t) << endl;
  17.         return 0;
  18.     }
  19.     int toSeconds(Time now)
  20.     {
  21.         return 3600 * now.hours + 60 * now.minutes + now.seconds;
  22.     }

a) 19845
b) 20000
c) 15000
d) 19844
View Answer

Answer: a
Explanation: In this program, we are just converting the given hours and minutes into seconds.
Output:

$ g++ stu1.cpp
$ a.out
Total seconds:19845

7. What will be the output of this program?

advertisement
  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         struct ShoeType 
  6.         {
  7.            string style;
  8.            double price;
  9.         };
  10.          ShoeType shoe1, shoe2;
  11.          shoe1.style = "Adidas";
  12.          shoe1.price = 9.99;
  13.          cout << shoe1.style << " $ "<< shoe1.price;
  14.          shoe2 = shoe1;
  15.          shoe2.price = shoe2.price / 9;
  16.          cout << shoe2.style << " $ "<< shoe2.price;
  17.          return 0;
  18.     }

a) Adidas $ 9.99Adidas $ 1.11
b) Adidas $ 9.99Adidas $ 9.11
c) Adidas $ 9.99Adidas $ 11.11
d) none of the mentioned
View Answer

Answer: a
Explanation: We copied the value of shoe1 into shoe2 and divide the shoe2 value by 9, So this is the output.
Output:

$ g++ stu2.cpp
$ a.out
Adidas $ 9.99
Adidas $ 1.11

8. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     struct sec 
  4.     {
  5.         int a;
  6.         char b;
  7.     };
  8.     int main()
  9.     {
  10.         struct sec s ={25,50};
  11.         struct sec *ps =(struct sec *)&s;
  12.         cout << ps->a << ps->b;
  13.         return 0;
  14.     }

a) 252
b) 253
c) 254
d) 262
View Answer

Answer: a
Explanation: In this program, We are dividing the values of a and b, printing it.
Output:

$ g++ stu5.cpp
$ a.out
252

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;};
View Answer

Answer: d
Explanation: option struct {int a;} is not correct because name of structure and ;(after declaration) are missing. In option struct a_struct {int a;} ; is missing. In option struct a_struct int a; {} are missing.

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

Answer: a
Explanation: Because arrow operator(->) is used to access members of structure pointer whereas dot operator(.) is used to access normal structure variables.

Sanfoundry Global Education & Learning Series – C++ Programming Language.

C++ Practice Resources
C++ Mock Tests & Certification Test | 1000 C++ MCQs | 1000 C++ Algorithms | Best C++ Books
« Prev Page - C++ Programming Questions and Answers – Pointer to Void
» Next Page - C++ Programming Questions and Answers – Operators

« C++ Programming Questions and Answers – Pointer to Void
C++ Programming Questions and Answers – Operators »
advertisement

Deep Dive @ Sanfoundry:

  1. Java Programming Examples on Inheritance
  2. Prestressed Concrete Structures Questions and Answers
  3. Programming Questions and Answers
  4. Design of Steel Structures Questions and Answers
  5. C++ Programming Examples on Data-Structures
  6. Java Programming Examples on Classes
  7. C# Programming Examples on Data Structures
  8. C Programming Examples on Data-Structures
  9. Object Oriented Programming Questions and Answers
  10. Java Programming Examples on Data-Structures
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below:
LinkedIn | Facebook | Twitter | Google+

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
Terms
Privacy Policy
Jobs
Bangalore Training
Online Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry. All Rights Reserved.