Languages [TCS Placement]: Sample Questions 46 - 47 of 131

Get unlimited access to the best preparation resource for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 46

Edit

Describe in Detail

Essay▾

What are compound statements?

Explanation

  • Compound statements are made up of two or more program statements that are executed together.
  • This usually occurs when statements are executed with TRUE or FALSE evaluation.
  • Compound statements can also be executed within a loop.
  • Curly brackets {} are placed before and after compound statements.
  • A compound statement (also called a “block” ) typically appears as the body of another statement, such as the “if statement” , “for statement” , “while statement” with several individual statements enclosed within a pair of braces {} .
  • Individual statements may themselves be expression statements, compound statements or control statements.
  • Unlike expression statements, a compound statement does not end with a semicolon.
  • A typical compound statement:
  1. {
  2.     pi=3.14;
  3.     area=piradiusradius;
  4. }
  • The particular compound statement consists of two assignment-type statements.

Question 47

Edit

Describe in Detail

Essay▾

What are code contracts?

Explanation

  • Code contracts express the code assumptions and statements- behavior of code in a language-neutral way.
  • Contracts included in the form of pre-conditions, post-conditions, and object-invariants.
  • Contracts improve testing by enabling run-time checking, static contract verification, and documentation generation.
  • The System. Diagnostics. Contracts namespace contains static classes used to express contracts.
  • The benefits of code contracts include:
  • Improved testing: provide static contract verification, runtime checking, and documentation generation.
  • Automatic testing tools: generate meaningful unit tests by filtering out meaningless test arguments that do not satisfy preconditions.
  • Static verification: static checker checks for contract violations without running the program. Checks implicit contracts, such as null dereferences and array bounds, and explicit contracts.
  • Reference documentation: Documentation generator augments existing XML documentation files with contract information. Generated documentation pages can also have contract sections.

Developed by: