All the programs are tested under Turbo C/C++ compilers.It is assumed that,



Programs run under DOS environment,



The underlying machine is an x86 system,



Program is compiled using Turbo C/C++ compiler.The program output may depend on the information based on this assumptions (forexample sizeof(int) == 2 may be assumed).Predict the output or error(s) for the following:

1. void main(){ int const * p=5; printf("%d",++(*p)); }

Answer:

Compiler error: Cannot modify a constant value.

Explanation

:p is a pointer to a "constant integer". But we tried to change the value of the"constant integer".

the values cannot bepredicted exactly. Depending on the number of bytes, the precession with of the valuerepresented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9with less precision than long double.

Rule of Thumb:

Never compare or at-least be cautious when using floating point numberswith relational operators

(

== , >, <, <=, >=,!=

)

.

4. main(){ static int var = 5; printf("%d ",var--); if(var)main(); }

Answer:

5 4 3 2 1

Explanation:

When

static

storage class is given, it is initialized once. The change in thevalue of a

static

variable is retained even between the function calls. Main is also treated likeany other ordinary function, which can be called recursively.