Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 44 - 45 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 44

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Define precondition and post-condition to a member function.

Explanation

Precondition: A precondition is a condition that must be true on entry to a member function.

  • If a class is used correctly- preconditions are never false.
  • For example, the interface invariants of stack class say nothing about pushing another element on full stack.
  • Thus! isful () is a precondition of the push operation.
Define the Java Basic Precondition Example

Post-Condition: A post-condition is a condition that must be true on exit from a member function if the precondition was valid on entry to that function.

  • A class is implemented correctly if post-conditions are never false.
  • For example, after pushing an element on the stack, we know that! isempty () must necessarily hold- a post-condition of the push operation.
Define the Example of Post Condition in Loop

Question 45

C & C Plus Plus
Edit

Describe in Detail

Essay▾
  1. voidmain ()
  2. {
  3.     char ⚹s =“⧵12345s”;
  4.     printf ( “%d”, sizeof (s) );
  5. }

Explanation

  • In the progam
Table Showing the Program
char ⚹ s = “⧵12345s” ;
  • Define the character pointer s and its value
printf ( “% d” , sizeof (s) ) ;
  • Printf prints the size of s in bytes, remember s is the pointer
  • For a 32 bit computer, the pointer size is 4 bytes
  • 64 bit computers have 8 byte pointer size, however, a 64bit computer running a 32bit OS will have 4 byte pointer.
  • Thus, under a specific architecture, all types of pointers (void ⚹ , int ⚹ , char ⚹ , long ⚹ etc) will have same size (except function pointers) .

Developed by: