Vous êtes sur la page 1sur 5

3.

PreProcessors:
Preprocessors are the part of C++ programming which are compiled before the compilation of the main programs.It is also known as Preprocessors compilation andd the time taken to compile the preprocessors is kenown as PreCompilation Time.

Name #define

Function of the preprocessor You can use the #define directive to give a meaningful name to a constant in your program. The #include directive tells the preprocessor to treat the contents of a specified file as if those contents had appeared in the source program at the point where the directive appears. You can organize constant and macro definitions into include files and then use #include directives to add these definitions to any source file. Include files are also useful for incorporating declarations of external variables and complex data types. You only need to define and name the types once in an include file created for that purpose. Error directives produce compiler-time error messages. The #ifdef and #ifndef directives perform the same task as the #if directive when it is used with defined( identifier ).

#include

#error #ifdef & #ifndef

The #if directive, with the #elif, #else, and #endif directives, controls compilation of portions of a source file. If the expression you write (after the #if) has a nonzero value, the line group #if,#elif,#else,#endif immediately following the #if directive is retained in the translation unit. The #pragma directives offer a way for each compiler to offer machine- and operating-system-specific features while retaining overall compatibility with the C and C++ languages. Pragmas are machine- or operating-system-specific by definition, and are usually different for every compiler. The #import directive is used to incorporate information from a type library. The content of the type library is converted into C++ classes, mostly describing the COM interfaces. The #line directive tells the preprocessor to change the compilers internally stored line number and filename to a given line number and filename. The compiler uses the line number and filename to refer to errors that it finds during compilation. The line number usually refers to the current input line, and the filename refers to the current input file. The line number is incremented after each line is

#pragma

#import #line

processed. #undef As its name implies, the #undef directive removes (undefines) a name previously created with #define

4.Variables:
What are Variables? Variable is a name location in memory that is user to hold a value that may be modified by the program.All variables must be declared before can be used. Syntax: <data_type> <variable_name>; Where are Vaiables declared? Variables will be declared in three basc places:

Location of declarations inside Functions In the definition of function parameters Outside of all functions a.Local Variables:

Name of the variable Local variables Formal parameters Global Variables

variables that are declared inside a function are called local variables.In some cases C/C+ + literature,these variables are referred to as automatic variables. Local variabels may be referenced only by statements that are inside the block in which the variables are declared.In other words,local variables are not known outside their own code block. Example:

void func1(void) { int x; x=10; } void func1(void) { int x; x=-199; } In the above example x is declared twice in function func1() and func2().The x in the func1() has no bearing on or relationship to the x in func2().This is because each x is only known to the code within the same block as the variable declaration. b.Formal Parameters: If a function is to use arguments, it must declare variables that will accept the values of the arguments. These variables are called the formal parameters of the functions. They behave like any other local variables inside the functions. As shown in the following example, their declaration occurs after the function name and inside the parenthesis. Example: /*Return 1 if c is a part of string s*/ int is_in*char *s , char c) { while (*s) if(*s == c) return 1; else s++; return 0; } The function is_in() has two parameters: s and c.This functions returns 1 if the character specified in c is containded within the string s;if it is not. c.Global Variables: Unlike local variables,global variables are known are known throughout the program and may be used by any piece of code.Also,they willhold heir value throughout the programs execution.You create gloable variables by declaring them outside of any functions.any expression can access them.

Example:

#include <iostream.h> o:p> int count; void finc1(void); void func2(void); int main(void) { count = 100; func1(); return 0; } void func1(void) { int temp; temp=count; func2(); cout<<Count is <<count; } void func2(void) { int count; for(count=1;count<10;count++)

putchar(.); }

Vous aimerez peut-être aussi