Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 118 - 119 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 118

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output for the program given below

  1. typedefenumerrorType { warning, error, exception, }error;
  2. main ()
  3. {
  4.     errorg1;
  5.     g1 =1;
  6.     printf ( “%d” ,g1);
  7. }

Explanation

  • Compiler error: Multiple declaration for error
  • In the program
  • The name error is used with the two meanings.
  • One means that it is an enumerator constant with value 1.
  • Another use is that it is a type name (due to typedef) for enumerrorType.
  • Given a situation the compiler cannot distinguish
Table Shows the Program Error
error g1g1 = error;
  • When the compiler can distinguish between usages then it will not issue error
  • Names canonly be overloaded in different namespaces.
  • Note: the extra comma in the declaration.
Table Shows the Program Error
enum errorType {warning, error, exception,}
  • Is not an error. An extra comma is valid and is provided just for programmer՚s convenience.

Question 119

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is abstraction?

Explanation

Understanding of Data Abstract
  • Data abstraction is key concept in object-oriented programming in C ++ .
  • Abstraction displays only the essential information and hiding the (implementation) details.
  • Abstraction provides the interface to the user without bothering him about the implementation. For example when using the mobile phone user only interacts with the screen elements without being concerned about phone՚s innards.

Abstraction using classes:

  • We implement abstraction in C ++ using classes.
  • Classes group data members and member functions using available access specifiers.
  • Class implementer decides which data member will be visible to outside world.

Abstraction in header files:

  • One more abstraction in C ++ is header files.
  • For example consider the pow () method present in math. h header file.
  • We call the function pow () present in the math. h header file and pass the number argument without worrying about the implementation.

Developed by: