C++Variables and types




Variables and types


The usefulness of the "Hello World" programs shown in the previous chapter is rather questionable. We had to write several lines of code, compile them, and then execute the resulting program, just to obtain the result of a simple sentence written on the screen. It certainly would have been much faster to type the output sentence ourselves.

However, programming is not limited only to printing simple texts on the screen. In order to go a little further on and to become able to write programs that perform useful tasks that really save us work, we need to introduce the concept of variable.

Let's imagine that I ask you to remember the number 5, and then I ask you to also memorize the number 2 at the same time. You have just stored two different values in your memory (5 and 2). Now, if I ask you to add 1 to the first number I said, you should be retaining the numbers 6 (that is 5+1) and 2 in your memory. Then we could, for example, subtract these values and obtain 4 as result.

The whole process described above is a simile of what a computer can do with two variables. The same process can be expressed in C++ with the following set of statements:










1
2
3
4


a = 5;
b = 2;
a = a + 1;
result = a - b;



Obviously, this is a very simple example, since we have only used two small integer values, but consider that your computer can store millions of numbers like these at the same time and conduct sophisticated mathematical operations with them.

We can now define variable as a portion of memory to store a value.

Each variable needs a name that identifies it and distinguishes it from the others. For example, in the previous code the variable names were a, b, and result, but we could have called the variables any names we could have come up with, as long as they were valid C++ identifiers.


Identifiers


A valid identifier is a sequence of one or more letters, digits, or underscore characters (_). Spaces, punctuation marks, and symbols cannot be part of an identifier. In addition, identifiers shall always begin with a letter. They can also begin with an underline character (_), but such identifiers are -on most cases- considered reserved for compiler-specific keywords or external identifiers, as well as identifiers containing two successive underscore characters anywhere. In no case can they begin with a digit.

C++ uses a number of keywords to identify operations and data descriptions; therefore, identifiers created by a programmer cannot match these keywords. The standard reserved keywords that cannot be used for programmer created identifiers are:

alignas, alignof, and, and_eq, asm, auto, bitand, bitor, bool, break, case, catch, char, char16_t, char32_t, class, compl, const, constexpr, const_cast, continue, decltype, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, noexcept, not, not_eq, nullptr, operator, or, or_eq, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_assert, static_cast, struct, switch, template, this, thread_local, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while, xor, xor_eq

Specific compilers may also have additional specific reserved keywords.

Very important: The C++ language is a "case sensitive" language. That means that an identifier written in capital letters is not equivalent to another one with the same name but written in small letters. Thus, for example, the RESULTvariable is not the same as the result variable or theResult variable. These are three different identifiers identifiying three different variables.


Fundamental data types


The values of variables are stored somewhere in an unspecified location in the computer memory as zeros and ones. Our program does not need to know the exact location where a variable is stored; it can simply refer to it by its name. What the program needs to be aware of is the kind of data stored in the variable. It's not the same to store a simple integer as it is to store a letter or a large floating-point number; even though they are all represented using zeros and ones, they are not interpreted in the same way, and in many cases, they don't occupy the same amount of memory.

Fundamental data types are basic types implemented directly by the language that represent the basic storage units supported natively by most systems. They can mainly be classified into:

  • Character types: They can represent a single character, such as 'A' or '$'. The most basic type is char, which is a one-byte character. Other types are also provided for wider characters.

  • Numerical integer types: They can store a whole number value, such as 7 or 1024. They exist in a variety of sizes, and can either be signed or unsigned, depending on whether they support negative values or not.

  • Floating-point types: They can represent real values, such as 3.14 or 0.01, with different levels of precision, depending on which of the three floating-point types is used.

  • Boolean type: The boolean type, known in C++ as bool, can only represent one of two states, true or false.


Here is the complete list of fundamental types in C++:



























































































GroupType names*Notes on size / precision
Character typescharExactly one byte in size. At least 8 bits.
char16_tNot smaller than char. At least 16 bits.
char32_tNot smaller than char16_t. At least 32 bits.
wchar_tCan represent the largest supported character set.
Integer types (signed)signed charSame size as char. At least 8 bits.
signed short intNot smaller than char. At least 16 bits.
signed intNot smaller than short. At least 16 bits.
signed long intNot smaller than int. At least 32 bits.
signed long long intNot smaller than long. At least 64 bits.
Integer types (unsigned)unsigned char(same size as their signed counterparts)
unsigned short int
unsigned int
unsigned long int
unsigned long long int
Floating-point typesfloat
doublePrecision not less than float
long doublePrecision not less than double
Boolean typebool
Void typevoidno storage
Null pointerdecltype(nullptr)

* The names of certain integer types can be abbreviated without their signed and int components - only the part not in italics is required to identify the type, the part in italics is optional. I.e., signed short int can be abbreviated assigned short, short int, or simply short; they all identify the same fundamental type.

Within each of the groups above, the difference between types is only their size (i.e., how much they occupy in memory): the first type in each group is the smallest, and the last is the largest, with each type being at least as large as the one preceding it in the same group. Other than that, the types in a group have the same properties.

Note in the panel above that other than char (which has a size of exactly one byte), none of the fundamental types has a standard size specified (but a minimum size, at most). Therefore, the type is not required (and in many cases is not) exactly this minimum size. This does not mean that these types are of an undetermined size, but that there is no standard size across all compilers and machines; each compiler implementation may specify the sizes for these types that fit the best the architecture where the program is going to run. This rather generic size specification for types gives the C++ language a lot of flexibility to be adapted to work optimally in all kinds of platforms, both present and future.

Type sizes above are expressed in bits; the more bits a type has, the more distinct values it can represent, but at the same time, also consumes more space in memory:




























SizeUnique representable valuesNotes
8-bit256= 28
16-bit65 536= 216
32-bit4 294 967 296= 232 (~4 billion)
64-bit18 446 744 073 709 551 616= 264 (~18 billion billion)

For integer types, having more representable values means that the range of values they can represent is greater; for example, a 16-bit unsigned integer would be able to represent 65536 distinct values in the range 0 to 65535, while its signed counterpart would be able to represent, on most cases, values between -32768 and 32767. Note that the range of positive values is approximately halved in signed types compared to unsigned types, due to the fact that one of the 16 bits is used for the sign; this is a relatively modest difference in range, and seldom justifies the use of unsigned types based purely on the range of positive values they can represent.

For floating-point types, the size affects their precision, by having more or less bits for their significant and exponent.

If the size or precision of the type is not a concern, thenchar, int, and double are typically selected to represent characters, integers, and floating-point values, respectively. The other types in their respective groups are only used in very particular cases.

The properties of fundamental types in a particular system and compiler implementation can be obtained by using thenumeric_limits classes (see standard header<limits>). If for some reason, types of specific sizes are needed, the library defines certain fixed-size type aliases in header <cstdint>.

The types described above (characters, integers, floating-point, and boolean) are collectively known as arithmetic types. But two additional fundamental types exist: void, which identifies the lack of type; and the type nullptr, which is a special type of pointer. Both types will be discussed further in a coming chapter about pointers.

C++ supports a wide variety of types based on the fundamental types discussed above; these other types are known as compound data types, and are one of the main strengths of the C++ language. We will also see them in more detail in future chapters.


Declaration of variables


C++ is a strongly-typed language, and requires every variable to be declared with its type before its first use. This informs the compiler the size to reserve in memory for the variable and how to interpret its value. The syntax to declare a new variable in C++ is straightforward: we simply write the type followed by the variable name (i.e., its identifier). For example:










1
2


int a;
float mynumber;



These are two valid declarations of variables. The first one declares a variable of type int with the identifier a. The second one declares a variable of type float with the identifier mynumber. Once declared, the variables a andmynumber can be used within the rest of their scope in the program.
If declaring more than one variable of the same type, they can all be declared in a single statement by separating their identifiers with commas. For example:










 


int a, b, c;



This declares three variables (a, b and c), all of them of typeint, and has exactly the same meaning as:










1
2
3


int a;
int b;
int c;



To see what variable declarations look like in action within a program, let's have a look at the entire C++ code of the example about your mental memory proposed at the beginning of this chapter:











1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23


// operating with variables

#include <iostream>
using namespace std;

int main ()
{
// declaring variables:
int a, b;
int result;

// process:
a = 5;
b = 2;
a = a + 1;
result = a - b;

// print out the result:
cout << result;

// terminate the program:
return 0;
}


4




Don't be worried if something else than the variable declarations themselves look a bit strange to you. Most of it will be explained in more detail in coming chapters.


Initialization of variables


When the variables in the example above are declared, they have an undetermined value until they are assigned a value for the first time. But it is possible for a variable to have a specific value from the moment it is declared. This is called the initialization of the variable.

In C++, there are three ways to initialize variables. They are all equivalent and are reminiscent of the evolution of the language over the years:

The first one, known as c-like initialization (because it is inherited from the C language), consists of appending an equal sign followed by the value to which the variable is initialized:

type identifier = initial_value;
For example, to declare a variable of type int called x and initialize it to a value of zero from the same moment it is declared, we can write:










 


int x = 0;



A second method, known as constructor initialization(introduced by the C++ language), encloses the initial value between parentheses (()):

type identifier (initial_value);
For example:










 


int x (0);



Finally, a third method, known as uniform initialization, similar to the above, but using curly braces ({}) instead of parentheses (this was introduced by the revision of the C++ standard, in 2011):

type identifier {initial_value};
For example:










 


int x {0}; 



All three ways of initializing variables are valid and equivalent in C++.











1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18


// initialization of variables

#include <iostream>
using namespace std;

int main ()
{
int a=5; // initial value: 5
int b(3); // initial value: 3
int c{2}; // initial value: 2
int result; // initial value undetermined

a = a + b;
result = a - c;
cout << result;

return 0;
}


6






Type deduction: auto and decltype


When a new variable is initialized, the compiler can figure out what the type of the variable is automatically by the initializer. For this, it suffices to use auto as the type specifier for the variable:










1
2


int foo = 0;
auto bar = foo; // the same as: int bar = foo;



Here, bar is declared as having an auto type; therefore, the type of bar is the type of the value used to initialize it: in this case it uses the type of foo, which is int.

Variables that are not initialized can also make use of type deduction with the decltype specifier:










1
2


int foo = 0;
decltype(foo) bar; // the same as: int bar;



Here, bar is declared as having the same type as foo.

auto and decltype are powerful features recently added to the language. But the type deduction features they introduce are meant to be used either when the type cannot be obtained by other means or when using it improves code readability. The two examples above were likely neither of these use cases. In fact they probably decreased readability, since, when reading the code, one has to search for the type of foo to actually know the type of bar.


Introduction to strings


Fundamental types represent the most basic types handled by the machines where the code may run. But one of the major strengths of the C++ language is its rich set of compound types, of which the fundamental types are mere building blocks.

An example of compound type is the string class. Variables of this type are able to store sequences of characters, such as words or sentences. A very useful feature!

A first difference with fundamental data types is that in order to declare and use objects (variables) of this type, the program needs to include the header where the type is defined within the standard library (header <string>):











1
2
3
4
5
6
7
8
9
10
11
12


// my first string
#include <iostream>
#include <string>
using namespace std;

int main ()
{
string mystring;
mystring = "This is a string";
cout << mystring;
return 0;
}


This is a string




As you can see in the previous example, strings can be initialized with any valid string literal, just like numerical type variables can be initialized to any valid numerical literal. As with fundamental types, all initialization formats are valid with strings:










1
2
3


string mystring = "This is a string";
string mystring ("This is a string");
string mystring {"This is a string"};



Strings can also perform all the other basic operations that fundamental data types can, like being declared without an initial value and change its value during execution:











1
2
3
4
5
6
7
8
9
10
11
12
13
14


// my first string
#include <iostream>
#include <string>
using namespace std;

int main ()
{
string mystring;
mystring = "This is the initial string content";
cout << mystring << endl;
mystring = "This is a different string content";
cout << mystring << endl;
return 0;
}


This is the initial string content
This is a different string content




Note: inserting the endl manipulator ends the line (printing a newline character and flushing the stream).

The string class is a compound type. As you can see in the example above, compound types are used in the same way as fundamental types: the same syntax is used to declare variables and to initialize them.

For more details on standard C++ strings, see the stringclass reference


//


// // <![CDATA[
(function(_){_.wa.prototype.Jm=_.p(1,function(){return null!=this.g[0]});var Li=function(a){this.g=a||[]};Li.prototype.aa=function(){return this.g};Li.prototype.Jm=function(){return null!=this.g[1]};Li.prototype.getDuration=function(){var a=this.g[1];return null!=a?a:0};var Mi=function(a){a=a.g[2];return null!=a?a:0},Ni=function(a){a=a.g[3];return null!=a?a:1};Li.prototype.qh=function(){var a=this.g[4];return null!=a?a:1};Li.prototype.um=function(){var a=this.g[5];return null!=a?a:0};var Oi=function(a){this.g=a||[]};Oi.prototype.aa=function(){return this.g};var Pi=function(a){this.A=a;this.da=null;this.fk=_.Je(this.A,"data-ifc");this.bp={};this.Kh=[];this.no=[];this.Jc={};this.ck=this.rA=null;this.hc=!!window.osdlamrc;for(a=0;a<this.fk.length;++a)for(var b=new Oi(JSON.parse(this.fk[a].getAttribute("data-ifc")||"[]")),c=0;c<_.ta(b.g,0);++c){var d;d=c;d=new Li(_.sa(b.g,0)[d]);this.Jc[d.qh()]=!0;this.no.push({Lv:0,uf:a,aj:!1,Ia:d})}this.A.forEachAd((0,_.A)(this.yA,this));_.G(_.N,"click",(0,_.A)(this.Bd,this),!0);this.hc&&(this.Jc[3]||this.Jc[6])&&window.osdlamrc((0,_.A)(_.xe("dom_ic::handle_osd",this.Cm,this,void 0),this));this.Jc[1]&&_.G(_.O,"load",(0,_.A)(this.Xh,this,1));this.Jc[4]&&_.G(_.N,"DOMContentLoaded",(0,_.A)(this.Xh,this,4));"undefined"!==typeof window.AFMA_Communicator&&window.AFMA_Communicator&&window.AFMA_Communicator.addEventListener&&this.Jc[2]&&window.AFMA_Communicator.addEventListener("onshow",(0,_.A)(this.Xh,this,2))},Qi=[1,2,4];Pi.prototype.yA=function(a){a.listen(0,_.Pa(this.A.g)?"touchstart":"mousedown",(0,_.A)(function(){this.da=a},this))};Pi.prototype.Bd=function(a){for(var b,c,d=-1,e=[],f=0;f<this.no.length;++f){var h=this.no[f];if(!(Mi(h.Ia)<=d||h.aj||!1===e[h.uf]))if(e[h.uf]||_.Mc(this.fk[h.uf],a.target)){e[h.uf]=!0;var k=a,m=h,n;if(!(n=m.Ia.Jm()&&!Ri(this,m))&&(n=null!=m.Ia.g[0]||null!=m.Ia.g[6])){var v=k,C=m,J=this.fk[C.uf].getBoundingClientRect(),m=J.width,k=J.height;n=v.clientX-J.left;J=v.clientY-J.top;if(!(0<m&&0v.clientX||0>v.clientY||0>n||0>J)m=!1;else{v=void 0;if(v=null!=C.Ia.g[0])v=C.Ia.g[0],v=Si(null!=v?v:""),v=!(n>=v.left&&J>=v.top&&m-n>=v.right&&k-J>=v.bottom);v||null==C.Ia.g[6]||(C=C.Ia.g[6],C=Si(null!=C?C:""),C.top*=k/100,C.bottom*=k/100,C.left*=m/100,C.right*=m/100,v=!(n>=C.left&&J>=C.top&&m-n>=C.right&&k-J>=C.bottom));v&&this.da&&this.da.creativeConversionUrl()&&(m=this.da.creativeConversionUrl()+"&label=blocked_border_click",_.Xc(_.O,m,void 0));m=v}n=!m}n||(c=h,b=Ni(h.Ia),d=Mi(h.Ia))}else e[h.uf]=!1}if(c){switch(Ni(c.Ia)){case 2:_.dd(a);break;case 3:this.A.fireOnObject("common_show_15overlay",a);this.da&&this.da.creativeConversionUrl()&&(d=this.da.creativeConversionUrl()+"&label=onepointfiveclick_first_click",_.Xc(_.O,d,void 0));_.dd(a);break;case 4:this.A.fireOnObject("should_expand_action_button",a),_.dd(a)}if(a=null!=c.Ia.g[7])a=++c.Lv,d=c.Ia.g[7],a=a>=(null!=d?d:0);a&&(c.aj=!0)}!this.Jc[5]||void 0!=b&&1!==b||this.Xh(5)};var Ri=function(a,b){var c=b.Ia.qh(),d=null,e=!1;switch(c){case 3:e=!0;d=a.Kh[Math.floor(20*b.Ia.um())];break;case 6:e=!0;d=a.bp[c];break;default:d=a.bp[c]}if(void 0===d)switch(e&&!a.hc&&(b.aj=!0),c){case 3:if(!a.Kh.length)return!1;break;case 4:case 1:break;default:return!1}if(void 0!==d&&(0,_.B)()>=d+b.Ia.getDuration())return-1=this.Kh.length){var b=a[7];if(b!==this.rA)for(var b=Math.floor(20*b),c=(0,_.B)(),d=this.Kh.length;d<=b;++d)this.Kh.push(c)}this.Jc[6]&&(a=a[20],a!==this.ck&&(!(0,window.isNaN)(this.ck)&&50// // <![CDATA[
(function(){var g,h=this,aa=function(a,b,c){return a.call.apply(a.bind,arguments)},ba=function(a,b,c){if(!a)throw Error();if(2<arguments.length){var d=Array.prototype.slice.call(arguments,2);return function(){var c=Array.prototype.slice.call(arguments);Array.prototype.unshift.apply(c,d);return a.apply(b,c)}}return function(){return a.apply(b,arguments)}},l=function(a,b,c){l=Function.prototype.bind&&-1!=Function.prototype.bind.toString().indexOf("native code")?aa:ba;return l.apply(null,arguments)},m=Date.now||function(){return+new Date};var n=String.prototype.trim?function(a){return a.trim()}:function(a){return a.replace(/^[sxa0]+|[sxa0]+$/g,"")},p=function(a,b){return ab?1:0};var q=function(a){return Array.prototype.concat.apply(Array.prototype,arguments)},ca=function(a){var b=a.length;if(0<b){for(var c=Array(b),d=0;dparseFloat(y)){x=String(D);break a}}x=y}var ia=x,ka={},la=function(a){if(!ka[a]){for(var b=0,c=n(String(ia)).split("."),d=n(String(a)).split("."),e=Math.max(c.length,d.length),f=0;0==b&&f<e;f++){var k=c[f]||"",A=d[f]||"",R=RegExp("(d*)(D*)","g"),ta=RegExp("(d*)(D*)","g");do{var B=R.exec(k)||["","",""],C=ta.exec(A)||["","",""];if(0==B[0].length&&0==C[0].length)break;b=p(0==B[1].length?0:parseInt(B[1],10),0==C[1].length?0:parseInt(C[1],10))||p(0==B[2].length,0==C[2].length)||p(B[2],C[2])}while(0==b)}ka[a]=0<=b}},ma=h.document,na=ma&&v?ha()||("CSS1Compat"==ma.compatMode?parseInt(ia,10):5):void 0;var E;if(!(E=!w&&!v)){var F;if(F=v)F=9<=Number(na);E=F}E||w&&la("1.9.1");v&&la("9");var G=document,H=window;var oa="StopIteration"in h?h.StopIteration:{message:"StopIteration",stack:""},I=function(){};I.prototype.next=function(){throw oa;};I.prototype.X=function(){return this};var J=function(a,b){this.m={};this.i=[];this.J=this.h=0;var c=arguments.length;if(1<c){if(c%2)throw Error("Uneven number of arguments");for(var d=0;d<c;d+=2)this.set(arguments[d],arguments[d+1])}else a&&this.addAll(a)};J.prototype.v=function(){K(this);for(var a=[],b=0;b2*this.h&&K(this),!0):!1};var K=function(a){if(a.h!=a.i.length){for(var b=0,c=0;b<a.i.length;){var d=a.i[b];L(a.m,d)&&(a.i[c++]=d);b++}a.i.length=c}if(a.h!=a.i.length){for(var e={},c=b=0;b<a.i.length;)d=a.i[b],L(e,d)||(a.i[c++]=d,e[d]=1),b++;a.i.length=c}};g=J.prototype;g.get=function(a,b){return L(this.m,a)?this.m[a]:b};g.set=function(a,b){L(this.m,a)||(this.h++,this.i.push(a),this.J++);this.m[a]=b};g.addAll=function(a){var b;if(a instanceof J)b=a.B(),a=a.v();else{b=[];var c=0,d;for(d in a)b[c++]=d;c=[];d=0;for(var e in a)c[d++]=a[e];a=c}for(e=0;e<b.length;e++)this.set(b[e],a[e])};g.forEach=function(a,b){for(var c=this.B(),d=0;d=d.i.length)throw oa;var e=d.i[b++];return a?e:d.m[e]};return e};var L=function(a,b){return Object.prototype.hasOwnProperty.call(a,b)};var pa=/^(?:([^:/?#.]+):)?(?://(?:([^/?#]*)@)?([^/#?]*?)(?::([0-9]+))?(?=[/#?]|$))?([^?#]+)?(?:?([^#]*))?(?:#(.*))?$/,qa=function(a,b){if(a)for(var c=a.split("&"),d=0;d<c.length;d++){var e=c[d].indexOf("="),f=null,k=null;0b)throw Error("Bad port number "+b);a.H=b}else a.H=null},ua=function(a,b,c){N(a);b instanceof P?(a.o=b,a.o.N(a.l)):(c||(b=Q(b,za)),a.o=new P(b,0,a.l))},N=function(a){if(a.ba)throw Error("Tried to modify a read-only Uri");};M.prototype.N=function(a){this.l=a;this.o&&this.o.N(a);return this};var O=function(a,b){return a?b?decodeURI(a.replace(/%25/g,"%2525")):decodeURIComponent(a):""},Q=function(a,b,c){return"string"==typeof a?(a=encodeURI(a).replace(b,Aa),c&&(a=a.replace(/%25([0-9a-fA-F]{2})/g,"%$1")),a):null},Aa=function(a){a=a.charCodeAt(0);return"%"+(a>>4&15).toString(16)+(a&15).toString(16)},va=/[#/?@]/g,xa=/[#?:]/g,wa=/[#?]/g,za=/[#?@]/g,ya=/#/g,P=function(a,b,c){this.h=this.g=null;this.j=a||null;this.l=!!c},S=function(a){a.g||(a.g=new J,a.h=0,a.j&&qa(a.j,function(b,c){a.add(decodeURIComponent(b.replace(/+/g," ")),c)}))};g=P.prototype;g.add=function(a,b){S(this);this.j=null;a=T(this,a);var c=this.g.get(a);c||this.g.set(a,c=[]);c.push(b);this.h+=1;return this};g.remove=function(a){S(this);a=T(this,a);return this.g.A(a)?(this.j=null,this.h-=this.g.get(a).length,this.g.remove(a)):!1};g.A=function(a){S(this);a=T(this,a);return this.g.A(a)};g.B=function(){S(this);for(var a=this.g.v(),b=this.g.B(),c=[],d=0;d<b.length;d++)for(var e=a[d],f=0;f<e.length;f++)c.push(b[d]);return c};g.v=function(a){S(this);var b=[];if("string"==typeof a)this.A(a)&&(b=q(b,this.g.get(T(this,a))));else{a=this.g.v();for(var c=0;c<a.length;c++)b=q(b,a[c])}return b};g.set=function(a,b){S(this);this.j=null;a=T(this,a);this.A(a)&&(this.h-=this.g.get(a).length);this.g.set(a,[b]);this.h+=1;return this};g.get=function(a,b){var c=a?this.v(a):[];return 0<c.length?String(c[0]):b};g.toString=function(){if(this.j)return this.j;if(!this.g)return"";for(var a=[],b=this.g.B(),c=0;c<b.length;c++)for(var d=b[c],e=encodeURIComponent(String(d)),d=this.v(d),f=0;f<d.length;f++){var k=e;""!==d[f]&&(k+="="+encodeURIComponent(String(d[f])));a.push(k)}return this.j=a.join("&")};g.clone=function(){var a=new P;a.j=this.j;this.g&&(a.g=this.g.clone(),a.h=this.h);return a};var T=function(a,b){var c=String(b);a.l&&(c=c.toLowerCase());return c};P.prototype.N=function(a){a&&!this.l&&(S(this),this.j=null,this.g.forEach(function(a,c){var d=c.toLowerCase();c!=d&&(this.remove(c),this.remove(d),0this.Y&&(this.G=-1,V(this,1,a),null!==this.s&&this.s.registerFinalizeCallback(l(this.s.fireOnObject,this.s,"attempt_survey_trigger",["wfocus",this.W,this.U,this.L,this.S,this.O,a])))}this.Z&&V(this,3)}};var Ba=function(a){if(null!==a.s){var b=l(function(a,b,c){this.L=b.fa().ea();this.L||(a=new M(b.da()),this.L=a.u+a.D);this.S=b.creativeConversionUrl();this.O=b.adGroupCreativeId();this.V(c)},a),c=a.R;a.s.forEachAd(function(a){a.forEachNavigationAdPiece(function(d){a.listen(d,c,b)})})}else{var d=l(a.V,a);da(H,a.R,d)}};W.prototype.V=function(a){this.P=a.button;this.M=!0;a=l(this.T,this);H.setTimeout(a,5E3)};W.prototype.T=function(){this.M=!1};var V=function(a,b,c){var d=["//",a.ca?"googleads.g.doubleclick.net":"pagead2.googlesyndication.com","/pagead/gen_204?id=wfocus","&gqid="+a.U,"&qqid="+a.W].join("");0==b&&(d+="&return=0");1==b&&(d+="&return=1&timeDelta="+c,a.$&&(d+="&cbtn="+a.P));2==b&&(d+="&bgload=1");3==b&&(d+="&fg=1");H.google_image_requests||(H.google_image_requests=[]);a=H.document.createElement("img");a.src=d;H.google_image_requests.push(a)},U=function(a){return"undefined"!==typeof a};var Ca=function(a,b,c,d,e,f,k,A){return new W(null,a,b,c,d,e,f,k,A)},X=["wfocusnhinit"],Y=h;X[0]in Y||!Y.execScript||Y.execScript("var "+X[0]);for(var Z;X.length&&(Z=X.shift());)X.length||void 0===Ca?Y=Y[Z]?Y[Z]:Y[Z]={}:Y[Z]=Ca;}).call(this);wfocusnhinit("-3TVVrD8OZfJWOmEndAE","CJvxpsKpn8sCFc2fFgodRVsPSg",true,true,true,false,false,0);
// ]]>// g?c=a+f+c:(g+=f.length,f=a.indexOf("&",g),c=0<=f?a.substring(0,g)+c+a.substring(f):a.substring(0,g)+c)}return 2E3<c.length?void 0!==d?ca(a,b,d,void 0,e):a:c};var da=function(){var a=/[&?]exk=([^& ]+)/.exec(p.location.href);return a&&2==a.length?a[1]:null};var q=function(a,b){this.width=a;this.height=b};q.prototype.round=function(){this.width=Math.round(this.width);this.height=Math.round(this.height);return this};var ea=function(a,b){for(var c in a)Object.prototype.hasOwnProperty.call(a,c)&&b.call(void 0,a[c],c,a)},ga=function(){var a=fa;if(!a)return"";var b=/.*[&#?]google_debug(=[^&]*)?(&.*)?$/;try{var c=b.exec(decodeURIComponent(a));if(c)return c[1]&&1b)f=ia(a,b+1);else if(0===a||a)f=String(a);f&&c.push(e+"="+encodeURIComponent(f))});return c.join("&")},r=function(a,b,c){a.google_image_requests||(a.google_image_requests=[]);var d=a.document.createElement("img");if(c){var e=function(a){c(a);a=e;d.removeEventListener?d.removeEventListener("load",a,!1):d.detachEvent&&d.detachEvent("onload",a);a=e;d.removeEventListener?d.removeEventListener("error",a,!1):d.detachEvent&&d.detachEvent("onerror",a)};ha(d,"load",e);ha(d,"error",e)}d.src=b;a.google_image_requests.push(d)};var ja=function(a,b,c){this.v=a;this.u=b;this.c=c;this.f=null;this.s=this.g;this.A=!1},ka=function(a,b,c){this.message=a;this.fileName=b||"";this.lineNumber=c||-1},ma=function(a,b,c){var d;try{d=c()}catch(g){var e=a.c;try{var f=la(g),e=a.s.call(a,b,f,void 0,void 0)}catch(l){a.g("pAR",l)}if(!e)throw g;}finally{}return d},u=function(a,b){var c=na;return function(){var d=arguments;return ma(c,a,function(){return b.apply(void 0,d)})}};ja.prototype.g=function(a,b,c,d,e){var f={};f.context=a;b instanceof ka||(b=la(b));f.msg=b.message.substring(0,512);b.fileName&&(f.file=b.fileName);0<b.lineNumber&&(f.line=b.lineNumber.toString());a=h.document;f.url=a.URL.substring(0,512);f.ref=a.referrer.substring(0,512);if(this.f)try{this.f(f)}catch(l){}if(d)try{d(f)}catch(l){}d=this.v;try{if((this.A?d.w:Math.random())<(c||d.o)){var g=d.m+(e||this.u)+("&"+ia(f,1)),g=g.substring(0,2E3);r(h,g)}}catch(l){}return this.c};var la=function(a){var b=a.toString();a.name&&-1==b.indexOf(a.name)&&(b+=": "+a.name);a.message&&-1==b.indexOf(a.message)&&(b+=": "+a.message);if(a.stack){var c=a.stack,d=b;try{-1==c.indexOf(d)&&(c=d+"n"+c);for(var e;c!=e;)e=c,c=c.replace(/((https?:/..*/)[^/:]*:d+(?:.|n)*)2/,"$1");b=c.replace(/n */g,"n")}catch(f){b=d}}return new ka(b,a.fileName,a.lineNumber)};var oa=String.prototype.trim?function(a){return a.trim()}:function(a){return a.replace(/^[sxa0]+|[sxa0]+$/g,"")},pa=function(a,b){return ab?1:0};var qa=Array.prototype.indexOf?function(a,b,c){return Array.prototype.indexOf.call(a,b,c)}:function(a,b,c){c=null==c?0:0>c?Math.max(0,a.length+c):c;if(k(a))return k(b)&&1==b.length?a.indexOf(b,c):-1;for(;c<a.length;c++)if(c in a&&a[c]===b)return c;return-1},ra=Array.prototype.map?function(a,b,c){return Array.prototype.map.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=Array(d),f=k(a)?a.split(""):a,g=0;gparseFloat(Ca)){Ba=String(Ea);break a}}Ba=Ca}var Fa=Ba,Ga={},A=function(a){var b;if(!(b=Ga[a])){b=0;for(var c=oa(String(Fa)).split("."),d=oa(String(a)).split("."),e=Math.max(c.length,d.length),f=0;0==b&&f<e;f++){var g=c[f]||"",l=d[f]||"",S=RegExp("(d*)(D*)","g"),t=RegExp("(d*)(D*)","g");do{var K=S.exec(g)||["","",""],L=t.exec(l)||["","",""];if(0==K[0].length&&0==L[0].length)break;b=pa(0==K[1].length?0:parseInt(K[1],10),0==L[1].length?0:parseInt(L[1],10))||pa(0==K[2].length,0==L[2].length)||pa(K[2],L[2])}while(0==b)}b=Ga[a]=0<=b}return b},Ha=h.document,Ia=Ha&&y?Aa()||("CSS1Compat"==Ha.compatMode?parseInt(Fa,10):5):void 0;!z&&!y||y&&9<=Number(Ia)||z&&A("1.9.1");y&&A("9");var B=document,p=window;var C=null,Ja=function(){if(!B.body)return!1;if(!C){var a=B.createElement("iframe");a.style.display="none";a.id="anonIframe";C=a;B.body.appendChild(a)}return!0};var na;na=new ja(new function(){this.m="http"+("http:"===p.location.protocol?"":"s")+"://pagead2.googlesyndication.com/pagead/gen_204?id=";this.o=.01;this.w=Math.random()},"jserror",!0);var D=function(a,b){return u(a,b)};y&&A("9");!za||A("528");z&&A("1.9b")||y&&A("8")||xa&&A("9.5")||za&&A("528");z&&!A("8")||y&&A("9");var Ka=function(a,b,c){if("array"==aa(b))for(var d=0;d<b.length;d++)Ka(a,String(b[d]),c);else null!=b&&c.push("&",a,""===b?"":"=",encodeURIComponent(String(b)))},La=function(a,b,c){for(c=c||0;c<b.length;c+=2)Ka(b[c],b[c+1],a);return a},Ma=function(a,b){var c=2==arguments.length?La([a],arguments[1],0):La([a],arguments,1);if(c[1]){var d=c[0],e=d.indexOf("#");0e?c[1]="?":e==d.length-1&&(c[1]=void 0)}return c.join("")};var Na=0,E={},Pa=function(a){var b=E.imageLoadingEnabled;if(null!=b)a(b);else{var c=!1;Oa(function(b,e){delete E[e];c||(c=!0,null!=E.imageLoadingEnabled||(E.imageLoadingEnabled=b),a(b))})}},Oa=function(a){var b=new Image,c,d=""+Na++;E[d]=b;b.onload=function(){clearTimeout(c);a(!0,d)};c=setTimeout(function(){a(!1,d)},300);b.src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="},Qa=function(a){if(a){var b=document.createElement("OBJECT");b.data=a;b.width=1;b.height=1;b.style.visibility="hidden";var c=""+Na++;E[c]=b;b.onload=b.onerror=function(){delete E[c]};document.body.appendChild(b)}},Ra=function(a){if(a){var b=new Image,c=""+Na++;E[c]=b;b.onload=b.onerror=function(){delete E[c]};b.src=a}},Sa=function(a){Pa(function(b){b?Ra(a):Qa(a)})};var Ta={l:"ud=1",j:"ts=0",B:"sc=1",h:"gz=1",i:"op=1"};if(B&&B.URL){var fa=B.URL,Ua=!(fa&&0=b)){var d=0,e=function(){a();d++;db;){try{if(c.google_osd_static_frame)return c}catch(d){}try{if(c.aswift_0&&(!a||c.aswift_0.google_osd_static_frame))return c.aswift_0}catch(d){}b++;c=c!=c.parent?c.parent:null}return null},Za=function(a,b,c,d,e){if(10<Xa)p.clearInterval(M);else if(++Xa,p.postMessage&&(b.b||b.a)){var f=Ya(!0);if(f){var g={};H(b,g);g[0]="goog_request_monitoring";g[6]=a;g[16]=c;d&&d.length&&(g[17]=d.join(","));e&&(g[19]=e);try{var l=J(g);f.postMessage(l,"*")}catch(S){}}}},$a=function(a){var b=Ya(!1),c=!b;!b&&p&&(b=p.parent);if(b&&b.postMessage)try{b.postMessage(a,"*"),c&&p.postMessage(a,"*")}catch(d){}};var N=!1,O=function(a){if(a=a.match(/[d]+/g))a.length=3};(function(){if(navigator.plugins&&navigator.plugins.length){var a=navigator.plugins["Shockwave Flash"];if(a&&(N=!0,a.description)){O(a.description);return}if(navigator.plugins["Shockwave Flash 2.0"]){N=!0;return}}if(navigator.mimeTypes&&navigator.mimeTypes.length&&(a=navigator.mimeTypes["application/x-shockwave-flash"],N=!!a&&a.enabledPlugin)){O(a.enabledPlugin.description);return}try{var b=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");N=!0;O(b.GetVariable("$version"));return}catch(c){}try{b=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");N=!0;return}catch(c){}try{b=new ActiveXObject("ShockwaveFlash.ShockwaveFlash"),N=!0,O(b.GetVariable("$version"))}catch(c){}})();var ab=w("Firefox"),bb=wa()||w("iPod"),cb=w("iPad"),db=w("Android")&&!(va()||w("Firefox")||x()||w("Silk")),eb=va(),fb=w("Safari")&&!(va()||w("Coast")||x()||w("Edge")||w("Silk")||w("Android"))&&!(wa()||w("iPad")||w("iPod"));var P=function(a){return(a=a.exec(v))?a[1]:""};(function(){if(ab)return P(/Firefox/([0-9.]+)/);if(y||ya||xa)return Fa;if(eb)return P(/Chrome/([0-9.]+)/);if(fb&&!(wa()||w("iPad")||w("iPod")))return P(/Version/([0-9.]+)/);if(bb||cb){var a=/Version/(S+).*Mobile/(S+)/.exec(v);if(a)return a[1]+"."+a[2]}else if(db)return(a=P(/Androids+([0-9.]+)/))?a:P(/Version/([0-9.]+)/);return""})();var hb=function(){var a=p.parent&&p.parent!=p,b=a&&0<="//tpc.googlesyndication.com".indexOf(p.location.host);if(a&&p.name&&0==p.name.indexOf("google_ads_iframe")||b){var c;a=p||p;try{var d;if(a.document&&!a.document.body)d=new q(-1,-1);else{var e=(a||window).document,f="CSS1Compat"==e.compatMode?e.documentElement:e.body;d=(new q(f.clientWidth,f.clientHeight)).round()}c=d}catch(g){c=new q(-12245933,-12245933)}return gb(c)}c=p.document.getElementsByTagName("SCRIPT");return 0<c.length&&(c=c[c.length-1],c.parentElement&&c.parentElement.id&&0<c.parentElement.id.indexOf("_ad_container"))?gb(void 0,c.parentElement):null},gb=function(a,b){var c=ib("IMG",a,b);return c||(c=ib("IFRAME",a,b))?c:(c=ib("OBJECT",a,b))?c:null},ib=function(a,b,c){var d=document;c=c||d;d=a&&"*"!=a?a.toUpperCase():"";c=c.querySelectorAll&&c.querySelector&&d?c.querySelectorAll(d+""):c.getElementsByTagName(d||"*");for(d=0;d<c.length;d++){var e=c[d];if("OBJECT"==a)a:{var f=e.getAttribute("height");if(null!=f&&0<f&&0==e.clientHeight)for(var f=e.children,g=0;g<f.length;g++){var l=f[g];if("OBJECT"==l.nodeName||"EMBED"==l.nodeName){e=l;break a}}}f=e.clientHeight;g=e.clientWidth;if(l=b)l=new q(g,f),l=Math.abs(b.width-l.width)<.1*b.width&&Math.abs(b.height-l.height)<.1*b.height;if(l||!b&&10<f&&10<g)return e}return null};var Q=0,jb="",R=[],T=!1,U=!1,V=!1,kb=!0,lb=!1,mb=!1,nb=!1,ob=!1,pb=!1,qb=!1,rb=0,sb=0,W=0,tb=[],I=null,ub="",vb=[],wb=null,xb=[],yb=!1,zb="",Ab="",Bb=(new Date).getTime(),Cb=!1,Db="",Eb=!1,Fb=["1","0","3"],X=0,Y=0,Gb=0,Hb="",Jb=function(a,b,c){T&&(kb||3!=(c||3)||nb)&&Ib(a,b,!0);if(V||U&&mb)Ib(a,b),U=V=!1},Kb=function(){var a=wb;return a?2!=a():!0},Ib=function(a,b,c){if((b=b||ub)&&!yb&&(2==Y||c)&&Kb()){for(var d=0;d<R.length;++d){var e=Lb(R[d],b,c),f=a;lb?Sa(e):r(f,e,void 0)}pb=!0;c?T=!1:yb=!0}},Mb=function(a,b){var c=[];a&&c.push("avi="+a);b&&c.push("cid="+b);return c.length?"//pagead2.googlesyndication.com/activeview?"+c.join("&"):"//pagead2.googlesyndication.com/activeview"},Lb=function(a,b,c){c=c?"osdim":V?"osd2":"osdtos";a=[a,-1<a.indexOf("?")?"&id=":"?id=",c];"osd2"==c&&U&&mb&&a.push("&ts=1");a.push("&ti=1");a.push("&",b);a.push("&uc="+Gb);Cb?a.push("&tgt="+Db):a.push("&tgt=nf");a.push("&cl="+(Eb?1:0));qb&&(a.push("&lop=1"),b=m()-rb,a.push("&tslp="+b));b=a.join("");for(a=0;a<vb.length;a++){try{var d=vb[a]()}catch(e){}c="max_length";2<=d.length&&(3==d.length&&(c=d[2]),b=ca(b,encodeURIComponent(d[0]),encodeURIComponent(d[1]),c))}2E3<b.length&&(b=b.substring(0,2E3));return b},Z=function(a){if(zb){try{var b=ca(zb,"vi",a);Ja()&&r(C.contentWindow,b,void 0)}catch(c){}0<=qa(Fb,a)&&(zb="")}},Nb=function(){Z("-1")},Pb=function(a){if(a&&a.data&&k(a.data)){var b;var c=a.data;if(k(c)){b={};for(var c=c.split("n"),d=0;d=e)){var f=Number(c[d].substr(0,e)),e=c[d].substr(e+1);switch(f){case 5:case 8:case 11:case 15:case 16:case 18:e="true"==e;break;case 4:case 7:case 6:case 14:case 20:case 21:case 22:case 23:e=Number(e);break;case 3:case 19:if("function"==aa(decodeURIComponent))try{e=decodeURIComponent(e)}catch(l){throw Error("Error: URI malformed: "+e);}break;case 17:e=ra(decodeURIComponent(e).split(","),Number)}b[f]=e}}b=b[0]?b:null}else b=null;if(b&&(c=new G(b[4],b[12]),I&&I.match(c))){for(c=0;cX&&!U&&2==Y&&Qb(p,"osd2","hs="+X)},Sb=function(){var a={};H(I,a);a[0]="goog_dom_content_loaded";var b=J(a);try{Va(function(){$a(b)},10,"osd_listener::ldcl_int")}catch(c){}},Tb=function(){var a={};H(I,a);a[0]="goog_creative_loaded";var b=J(a);Va(function(){$a(b)},10,"osd_listener::lcel_int");Eb=!0},Ub=function(a){if(k(a)){a=a.split("&");for(var b=a.length-1;0<=b;b--){var c=a[b],d=Ta;c==d.l?(kb=!1,a.splice(b,1)):c==d.h?(W=1,a.splice(b,1)):c==d.j?(U=!1,a.splice(b,1)):c==d.i&&(lb=!0,a.splice(b,1))}Hb=a.join("&")}},Vb=function(){if(!Cb){var a=hb();a&&(Cb=!0,Db=a.tagName,a.complete||a.naturalWidth?Tb():F(a,"load",Tb,"osd_listener::creative_load"))}};n("osdlfm",D("osd_listener::init",function(a,b,c,d,e,f,g,l,S){Q=a;zb=b;Ab=d;T=f;g&&Ub(g);U=f;1==l?tb.push(947190538):2==l?tb.push(947190541):3==l&&tb.push(947190542);I=new G(e,da());F(p,"load",Nb,"osd_listener::load");F(p,"message",Pb,"osd_listener::message");jb=c||"";R=[Mb(c,S)];F(p,"unload",Rb,"osd_listener::unload");var t=p.document;!t.readyState||"complete"!=t.readyState&&"loaded"!=t.readyState?w("Trident")||w("MSIE")?F(t,"readystatechange",function(){"complete"!=t.readyState&&"loaded"!=t.readyState||Sb()},"osd_listener::rsc"):F(t,"DOMContentLoaded",Sb,"osd_listener::dcl"):Sb();-1==Q?Y=f?3:1:-2==Q?Y=3:0// // <![CDATA[
(function(_){var Pl=function(){this.Yh=[];this.No={}};Pl.prototype.report=function(){for(var a=[],b=0;b<this.Yh.length;++b)a.push(Ql(this.Yh[b]));return a};var Ql=function(a){var b=[a.key,a.value];_.r(a.lm)&&b.push(a.lm);return b},Rl={};var Sl={1:0,2:1,4:8,5:6,8:11,9:2,6:9,34:25,26:15,3:7,20:12,24:26},Tl=function(a,b,c){var d=Sl[b];"true"===c.getAttribute(b,"data-is-action-button-expanded")&&(d=12);(0,window.ja)(a,d)},Ul=function(a){return function(){a()}},Vl=function(a){return a.report()};_.t("registerAd",function(a,b){_.r(Rl[b])||(Rl[b]=new Pl);a.registerClickUrlModifier(_.ga(Vl,Rl[b]));for(var c=[1,2,4,8,6,9,5,3,20,34,26,24],d=0;d//

0/Post a Comment/Comments

Previous Post Next Post

Sidebar Ads

Ads1
Ads2