Saturday, January 29, 2011

Java programs examples

Java programs (source codes) examples



Conversion
of binary number to decimal number using java programming language

Decimal
to binary conversion in java

Check
leap year in java

Factorial
program in java

Multiplication
tables program in java

Prime
factors of a number in java

Floyd�s
triangle program in java

Swapping
two variables without using third variable in java

LCM
of two numbers

Saturday, January 22, 2011

#pragma warn directive in c









In c there are many warning messages which can be on or off with help of #pragma warn.



Syntax :




#pragma warn +xxx

#pragma warn �xxx

#pragma warn .xxx




Where

+ means on

- means off

. means on/off (toggle)





xxx is indicate particular warning code in thee alphabet. Example :



rvl is warning code which means function should return a value.




#include

#pragma

#pragma inline directive in c

#pragma inline directive in c

#pragma inline only tells the compiler that source code of program contain inline assembly language code .In in C we can write assembly language program with help of asm keyword.




Preprocessor definitions in c

Preprocessor directive in c

#include directive in c

# define directive in c

Pragma directive in c

#pragma startup and #pragma exit

#pragma inline

Preprocessor directives in c







In c all the preprocessor directives start with # character except define() operator. All the directives have different task which executes just before the actual execution of c program which makes the program more portable. These directives are used only to instruct compilers.




List all preprocessor directives in c.









Preprocessor definitions in c
Preprocessor directive in c
#

What is header file in c?







Include directory is special directory which content all the header files of c language. Extension of header files in c language is h. All header files only keep declaration of functions, declaration of data type and micro constants. Body of function i.e. function definition is not written in the header files. Hence no one can get source code of function like printf, clrscr etc. All the

Preprocessor definitions and directive in c




C preprocessor directives


All the preprocessors in c are not part of actual c programming language. When c language had introduced in the market there are different architecture of computers was present. To make the c language portable in different architectures or compilers, c language developer had introduced preprocessor. It is only instruction to compiler. All the preprocessor process

#include directive in c




Syntax:



#include

or

#include �filename�




Task of include directive is to include or import any type file. There are two form of include directive.




Form 1:



#include: This statement will search the file in include directory (Default location of include directory is c:\tc\include). If that file is present then #include statement is replaced by content of

# define directive in c





#
define directive by examples and questions with explanation in c



This directive is also called as Macro substitution directive. Syntax:




#define [(, ,...)]




Note: [] indicates optional term.



Task of macro substitution directive is to replace the identifier with corresponding Token_string. For example:




#include

#define

Pragma directive in c





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 simply ignore that pragma statement without showing any error or warning message and execute the whole program assuming this pragma

Preprocessor operators in c





There are two operators in c preprocessor:



1. # : This operator is called stringizing operator which convert any argument in the macro function in the string. So we can say pound sign # is string maker. Example




#include

#define string(s) #s

int main(){

char str[15]= string(World is our );

printf("%s",str);

return 0;

}




Output: World is our



Explanation :

# error directive in c



Syntax : #error



If compiler compiles this line then it shows a compiler fatal error i.e it only issue an error message and this error message includes . i.e it only issue an error message and this error message includes .

Example :




#include

#ifndef __MATH_H

#error First include then compile

#else

int main(){

float a,b=25;

a=sqrt(b);

printf("%f",a);

#line directive in c





It tells the compiler that next line of source code is at the line number which has been specified by constant in #line directive i.e it transfer the program control to the line number which has been specified by #line directive.

Example:




#include

#line 15

int main(){

int a=10;

a++;

a++;

#line 5

printf("%d",a);

}





If we will see its intermediate

#if directive in c




There are total six conditional compilation directives. There are:

(a)#if

(b)#elif

(c)#else

(d)#endif

(e)ifdef

(f)ifndef





#if directive :

It is conditional compilation directive. That is if condition is true then it will compile the c programming code otherwise it will not compile the c code.



Syntax 1:



#if

-------------

-------------

#

# elif in c




Processor directive #elif is part of #if directive. It will execute only if it�s just previous constant expression of #if or #elif is zero.



Syntax:



#if

------------------

------------------

#elif

------------------

------------------

����������.

���������..

#elif

------------------

----

define() preprocessor operator in c



define() preprocessor operator in c


#include

#define ABC 25

#if defined(ABC)

#define ABC 50

#undef ABC

#endif

int main(){

printf("%d",ABC+ABC);

return 0;

}








Output: Compilation error

#ifndef in c example






Directive #ifndef is just opposite to the directive #ifdef . In this case if identifier has not defined then #ifndef is true and if identifier has defined then #ifndef condition will false.



Syntax :



#ifndef

--------------

--------------

#else

--------------

--------------

#endif



Example 1:



#include

#define int �A�



int main(){

#undef in c


Explanation of #undef directives in c programming language by
examples, questions and answers



Directive #undef is used
to undefine any macro constants except global identifiers. It is useful when we
want to redefined any macro constants. For example:



#include

#define ABC
25

#ifdef ABC

#undef ABC

#define ABC 50

#else

#define ABC 100

#endif



int main(){

printf("%d"

#ifdef and #endif in c






Directive #ifdef is very similar to #if except its conditional statement which is identifier instead of a constant expression. Identifier may a macro constant or global identifier. It only checks identifier has been defied or not. It doesn�t care what the value of identifier is. If identifier has been defined then it executes #ifdef body otherwise it executes the body of #else directive.



Preprocessor in c


Preprocessor
tutorials in c programming language



Preprocessor definitions in c

Preprocessor directive in c

#include directive in c

# define directive in c

Pragma directive in c

#pragma startup and #pragma exit

#pragma inline direcive

Warning directive

Preprocessor operators in c

# if directive in c

#line directive in c

# error directive in c

# elif in c

# ifdef and #endif in c