While creating a networking application, you find a need to define a data type that can hold various data related to a network packet, such as its ID, source, destination, and payload. You also require a function to calculate the checksum of the packet. Which user-defined data type in C++ would be best suited for this use case? 

  • Class 
  • Struct 
  • Union 
  • Namespace
Classes in C++ are versatile data structures that can encapsulate both data members and member functions. In this scenario, since we need to define various data attributes for the packet and also include a function to calculate checksum, a class is the most appropriate choice.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *