© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

C and C++ Interview Questions

7. Describe #pragma directive in detail ?

Ans:

Pragma is implementation specific directive i.e each pragma directive has different implementation rule and use . There are many type of pragma directive and varies from one compiler to another compiler .If compiler does not recognize particular pragma the it ignore the pragma statement without showing any error or warning message and execute the whole program assuming this pragma statement is not present,
e.g
suppose any arbitrary pragma directive is #pragma world :

#pragma world
void main()
{
printf(“C is powerful language “);
}
Output : C is powerful language
Explanation:

Since #pragma world is unknown for Turbo c compiler so it ignore this directive without showing error or warning message and execute the whole program assuming #pragma world statement is not present.
List of pragma directive :
1. #pragma startup
2. #pragma exit
3. #pragma warn
4. #pragma option
5. #pragma inline
6. #pragma argsused
7. #pragma hdrfile
8. #pragma hdrstop
9. #pragma saveregs

Ex - 1: What is the hidden bug with the following  statement?
assert(val++ != 0);

Answer & Explanation:

Assert macro is used for debugging and removed in release version. In assert, the experssion involves side-effects. So the behavior of the code becomes different in case of debug version and the release version thus leading to a subtle bug.
Rule to Remember:
Don’t use expressions that have side-effects in assert statements. 


SLogix Student Projects
bottom