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 (for example sizeof(int) == 2 may be assumed). Predict the output or error(s) for the following:i) 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".

Questions by Beena   answers by Beena

Showing Answers 1 - 4 of 4 Answers

sam

  • Mar 1st, 2006
 

error: increment of read-only location

  Was this answer useful?  Yes

Cranston Snord

  • Oct 15th, 2007
 

This is misleading in that "void main()" would also be a bad idea- can cause the application to crash in some runtime environments.  Best to use int main(int argc, char **argv) instead.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions