Curso de Programación en C/Prog41

De WikiCabal
Ir a la navegación Ir a la búsqueda

Prog41

 1 #include <stdio.h>
 2 
 3 int main( void )
 4 {
 5   puts( "\n\tOrden de Precedencia de operadores\n" );
 6   puts( "\t()");
 7   puts( "\t++, --, sizeof, (cast)" );
 8   puts( "\t/, *, %" );
 9   puts( "\t+, -" );
10   puts( "\t<, <=, >=, >" );
11   puts( "\t==, !=" );
12   puts( "\t&&" );
13   puts( "\t||" );
14   puts( "\t+=, -=, /=, *=, %=" );
15   puts( "\t=\n" );
16 
17   printf( "\t4 + 5 * 2 = %d\n", 4 + 5 * 2 );
18 
19   printf( "\t( 4 + 5 ) * 2 = %d\n\n", ( 4 + 5 ) * 2 );
20 
21   printf( "\t1 && 1 || 0 && 0 = %d\n", 1 && 1 || 0 && 0 );
22 
23   printf( "\t1 && ( 1 || 0 ) && 0 = %d\n\n", 1 && ( 1 || 0 ) && 0 );
24 
25   return 0;
26 }

Resultado

[rrc@Pridd CClase]$ gcc -Wall -O2 -o Prog41 Prog41.c
Prog41.c: In function ‘main’:
Prog41.c:23: warning: suggest parentheses around ‘&&’ within ‘||’
[rrc@Pridd CClase]$ ./Prog41

       Orden de Precedencia de operadores

       ()
       ++, --, sizeof, (cast)
       /, *, %
       +, -
       <, <=, >=, >
       ==, !=
       &&
       ||
       +=, -=, /=, *=, %=
       =

       4 + 5 * 2 = 14
       ( 4 + 5 ) * 2 = 18

       1 && 1 || 0 && 0 = 1
       1 && ( 1 || 0 ) && 0 = 0

Explicación