« Langage C++/Opérateurs » : différence entre les versions

Contenu supprimé Contenu ajouté
m Robot : Remplacement de texte automatisé (-%C3%A9 +é)
m Robot : Remplacement de texte automatisé (-(<\/?)source +\1syntaxhighlight)
Ligne 26 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
int x, y;
x = 5; //x = 5
y = 3; //y = 3
x = y; //x = 3 (valeur de y)
</syntaxhighlight>
</source>
}}
 
Ligne 47 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
int x, y;
x = 5;
y = 3;
x += y; //x = 8
</syntaxhighlight>
</source>
}}
 
Ligne 68 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
int x, y;
x = 5;
y = 3;
x -= y; //x = 2
</syntaxhighlight>
</source>
}}
 
Ligne 89 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp" >
int x, y;
x = 5;
y = 3;
x *= y; //x = 15
</syntaxhighlight>
</source>
}}
 
Ligne 110 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
int x, y;
x = 5;
y = 3;
x /= y; //x = 1 (voir l'opérateur "/")
</syntaxhighlight>
</source>
}}
 
Ligne 131 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
int x, y;
x = 5;
y = 3;
x %= y; //x = 2 (voir l'opérateur "%")
</syntaxhighlight>
</source>
}}
 
Ligne 149 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
int x, y, z;
x = 5;
y = 3;
z = x + y; //z = 8
</syntaxhighlight>
</source>
}}
 
Ligne 164 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
int x, y, z;
x = 5;
y = 3;
z = x - y; //z = 2
</syntaxhighlight>
</source>
}}
 
Ligne 179 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
int x, y, z;
x = 5;
y = 3;
z = x * y; //z = 15
</syntaxhighlight>
</source>
}}
 
Ligne 194 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
int x, y, z;
x = 5;
Ligne 203 :
o = 3.0;
p = r / o; // p ~= 1.666666…
</syntaxhighlight>
</source>
 
En c++ la division est entière si les deux opérandes sont entiers. Si l'un des opérandes est codé sur un format réel alors le résultat sera réel.
Ligne 215 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
int x, y, z;
x = 5;
y = 3;
z = x % y; // = 2 (5 / 3 => quotient 1, reste 2)
</syntaxhighlight>
</source>
}}
 
Ligne 283 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
bool x, y;
x = true;
y = !x; // y = false
</syntaxhighlight>
</source>
}}
 
Ligne 295 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
bool x = true, y = true, z = false;
bool a, b, c;
Ligne 301 :
b = x && z; // b = false
c = x && !z; // c = true
</syntaxhighlight>
</source>
}}
 
Ligne 315 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
int a = 2, b = 6, c = 12, d, e;
d = a & b ; // d = 2
e = b & c ; // e = 4
</syntaxhighlight>
</source>
}}
 
Ligne 327 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
int a = 2, b = 6, c = 12, d, e;
d = a | b ; // d = 6
e = b | c ; // e = 14
</syntaxhighlight>
</source>
}}
 
Ligne 339 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
int a = 2, b = 6, c = 12, d, e, f;
d = a ^ b ; // d = 4
e = a ^ a ; // e = 0
f = a ^ c ; // f = 14
</syntaxhighlight>
</source>
}}
 
Ligne 352 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
int a = 2, b = -6, c = 0;
a = ~a ; // a = -3
b = ~b ; // b = 5
c = ~c ; // c = -1
</syntaxhighlight>
</source>
}}
 
Ligne 375 :
| contenu =
'''Syntaxe :'''
<sourcesyntaxhighlight lang="cpp">
 
++<operande>
 
</syntaxhighlight>
</source>
}}
Où ''operande'' est la valeur à incrémenter puis à renvoyer.
Ligne 388 :
| contenu =
'''Syntaxe :'''
<sourcesyntaxhighlight lang="cpp">
 
<operande>++
 
</syntaxhighlight>
</source>
}}
Où ''operande'' est la valeur à renvoyer puis à incrémenter.
Ligne 404 :
| contenu =
'''Syntaxe :'''
<sourcesyntaxhighlight lang="cpp">
 
--<operande>
 
</syntaxhighlight>
</source>
}}
Où ''operande'' est la valeur à décrémenter puis à renvoyer.
Ligne 417 :
| contenu =
'''Syntaxe :'''
<sourcesyntaxhighlight lang="cpp">
 
<operande>--
 
</syntaxhighlight>
</source>
}}
Où ''operande'' est la valeur à renvoyer puis à décrémenter.
Ligne 431 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
int a = 0;
 
++a = a++; // <-- résultat indéterminé
</syntaxhighlight>
</source>
}}
Dans ce cas, "a" peut valoir 1 ou 2 selon comment le compilateur a traité les opérateurs.
Ligne 442 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
int a = 0;
 
a = a++ + ++a + a++; // <-- résultat indéterminé
</syntaxhighlight>
</source>
}}
 
Ligne 455 :
| contenu =
 
<sourcesyntaxhighlight lang="cpp">
int a = 0;
int b = 5;
printf("%d, %d", a++, a = --b); // <-- résultat indéterminé
</syntaxhighlight>
</source>
}}
 
Ligne 472 :
| contenu = Le code ci-dessous filtre dans tab les entiers superieurs à 5 et les place dans filtered_tab.
 
<sourcesyntaxhighlight lang="cpp">
 
int tab[10];
Ligne 493 :
*/
}
</syntaxhighlight>
</source>
}}