Читайте также: |
|
Pointers
The index contains the memory address. When your program transfers the massif (for example, a symbolical line) in the function, C ++ are transferred by the address of the first element of the massif. As a result absolutely usually for function to use the index for a symbolical line. To declare the index for a symbolical line, function simply precedes a name a variable asterisk, as shown below:
void some_function (char * string);
The asterisk which precedes a variable name, specifies C ++ that the variable will store the memory address — the index. The following PTR_STR.CPP program uses the index for a symbolical line in the show_string function for a conclusion of contents of a line on one symbol for once:
#include <iostream.h>
void show_string (char * string)
{
while (*string! = '\0')
{
cout <<* string;
string ++;
}
}
void main (void)
{
show_string ("We learn to program in language C ++! ");
}
Pay attention to the cycle while in the show_slring function. while condition (*string! = '\0') checks, whether the current symbol specified by means of the index of string, a NULL symbol which defines the last symbol of a line is. If the symbol not NULL, a cycle removes the current symbol by means of cout. Then operator of string ++; increases siring index in such a way that it points to the following symbol of a line. When the index of string indicates a NULL symbol, function already removed a line and the cycle comes to the end.
Difference of procedural programming to object-oriented programming.
Procedural programming
In procedural programing our code is organised into small "procedures" that use and change our data. In ColdFusion, we write our procedures as either custom tags or functions. These functions typically take some input, do something, then produce some output. Ideally your functions would behave as "black boxes" where input data goes in and output data comes out.
The key idea here is that our functions have no intrinsic relationship with the data they operate on. As long as you provide the correct number and type of arguments, the function will do its work and faithfully return its output.
Sometimes our functions need to access data that is not provided as a parameter, i.e., we need access data that is outside the function. Data accessed in this way is considered "global" or "shared" data.
So in a procedural system our functions use data they are "given" (as parameters) but also directly access any shared data they need.
Дата добавления: 2015-11-16; просмотров: 77 | Нарушение авторских прав
<== предыдущая страница | | | следующая страница ==> |
хартия переводчика | | | Object oriented programming |