InicioLinuxBooleanos en lenguaje C

Booleanos en lenguaje C

Linux•11/4/2012
//bool.c

#include <stdbool.h>
#include <stdio.h>
#include <string.h>

char* bool_to_str ( _Bool ) ;
_Bool str_to_bool ( const char* ) ;

int main(){
///variables
_Bool b0,b1 ;
b0 = true ;
b1 = false ;
/**
* Cuerpo
**/
printf ( " A N D n " ) ;
printf( "%d & %d = %d n" , b0 ,b1, b0 & b1 ) ;
printf( "%s & %s = %s n" , bool_to_str( b0 ) , bool_to_str( b1 ) , bool_to_str( b0 & b1 ) ) ;
printf("%d & %d = %d n" , str_to_bool( bool_to_str( b0 ) ) , str_to_bool(bool_to_str( b1 ) ) , str_to_bool( bool_to_str( b0 & b1 ) ) ) ;
printf ( "ORn" ) ;
printf ( "%d | %d = %d n" , b0 , b1 , b0 | b1 ) ;
printf ( "%s | %s = %s n" , bool_to_str( b0 ) , bool_to_str( b1 ) , bool_to_str ( b0 | b1 ) ) ;
printf ( "%d | %d = %d n" , str_to_bool( bool_to_str ( b0 ) ) , str_to_bool ( bool_to_str ( b1 ) ), str_to_bool( bool_to_str( b0 | b1 ) ) ) ;
printf ( "NOTn" ) ;
printf ( "!%d = %d n" , b0 , !b0 ) ;
printf ( "!%s = %s n" , bool_to_str( b0 ) , bool_to_str( !b0 ) ) ;
printf ( "!%d = %d n" , str_to_bool( bool_to_str ( b0 ) ) , str_to_bool ( bool_to_str( !b0 ) ) ) ;
return 0 ;
}
/*Funciones*/
char* bool_to_str( _Bool b )
{
if( b == false ) return "false" ;
return "true" ;
}
_Bool str_to_bool( const char *b )
{
if ( !strcmp ( b , "true" ) ) return true ;
return false;
}

//build

$ cc -o bool bool.c

//run

$ ./bool

//output

AND
1 & 0 = 0
true & false = false
1 & 0 = 0
OR
1 | 0 = 1
true | false = true
1 | 0 = 1
NOT
!1 = 0
!true = false
!1 = 0
Datos archivados del Taringa! original
1puntos
1,514visitas
0comentarios
Actividad nueva en Posteamelo
0puntos
12visitas
0comentarios
Dar puntos:

Dejá tu comentario

0/2000

Autor del Post

l
lexlawliet🇦🇷
Usuario
Puntos0
Posts3
Ver perfil →
PosteameloArchivo Histórico de Taringa! (2004-2017). Preservando la inteligencia colectiva de la internet hispanohablante.

CONTACTO

18 de Septiembre 455, Casilla 52

Chillán, Región de Ñuble, Chile

Solo correo postal

© 2026 Posteamelo.com. No afiliado con Taringa! ni sus sucesores.

Contenido preservado con fines históricos y culturales.